You are on page 1of 51

LXXT [[[ MIQ XL QMXXIPLIWWIR HI QSSHPI GSYVWI IHMX TLT#MH!

ZKYC77

Digital Electronics

Prof. Dr. Leitis,
THM ­ Technische Hochschule Mittelhessen,
University of Applied Sciences
Friedberg

1
2 Number Systems and Binary Arithmetic

2.1 The Decimal Number System


General expressions for real numbers

n−1
i n−1 n−2 1 0
Z = ∑ C i⋅B =C n−1⋅B
−1 −m
C n−2⋅B ...C 1⋅B C 0⋅B C −1⋅B ...C −m cdt B
i =−m

Floating point postition

Z real number n Number of digits


B Base or Radix i Order Number
c coefficient

For the decimal number system: B=10 and c={0 ...9}

For the binary number system: B=2 and c={0, 1}


2
2 Number Systems and Binary Arithmetic

Examples

256 = 200  50  6 = 2⋅102 5⋅101  6⋅100

107910 = 1000  000  70  9 = 1⋅103 0 ⋅102  7⋅101 9⋅100 =Z

4792,3810 = 4⋅103 7⋅102  9⋅101  2⋅100  3⋅10−1  8⋅10−2 =Z

27 D = 20  7 = 2⋅101 7⋅100

3
2 Number Systems and Binary Arithmetic

n−1
i
Conversion binary to decimal numbers: Z 10 =∑ C i⋅2 c={0,1 }
i =0

Algorithm for conversion of numbers of Algorithm for conversion of a decimal numbers


any radix to a decimal numbers Z: Z to numbers or any radix

S 1=C n−1 Z
=S 1 C1
B Remainder

S 2 =S 1⋅BC n−2 S1
=S 2 Remainder C2
B
S 3 =S 2⋅BC n−3 S2
=S 3 Remainder C3
B
⋮ ⋮
S n−1 =S n−2⋅BC 1 S n−2
=S n−1 Remainder
B C n−2
S n =S n−1⋅BC 0 S n−1
=S n Remainder C n−1
B
Z =S n 4
2 Number Systems and Binary Arithmetic

Decimal
Binary Number
Number
0 0 0 0 0
1 0 0 0 1
2 0 0 1 0
3 0 0 1 1
4 0 1 0 0
5 0 1 0 1
6 0 1 1 0
7 0 1 1 1
8 1 0 0 0
9 1 0 0 1
10 1 0 1 0
11 1 0 1 1
12 1 1 0 0
13 1 1 0 1
14 1 1 1 0
15 1 1 1 1 5
2 Number Systems and Binary Arithmetic

Conversion binary to fractional numbers:

Example Binary number

Decimal number

6
2 Number Systems and Binary Arithmetic

Exercises in a nutshell

52110= ???2 1012= ???10


8,51610= ???2 11011,1102= ???10
101001,01112=???10

52110= 10 0000 10012 1012= 5 10


8,51610= 1000,1000012 11011,1102= 27,75 10
101001,01112=41,4375 10
7
2 Number Systems and Binary Arithmetic
Decimal Binary Octal Hexadecimal
0 0000 00 0
1 0001 01 1
2 0010 02 2
3 0011 03 3
4 0100 04 4
5 0101 05 5
6 0110 06 6
7 0111 07 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F 8
2 Number Systems and Binary Arithmetic

Exercises in a nutshell

738= ???2
7538=???10
1000002=???8
6310=???8

738= 1110112
7538=49110
1000002=408
6310=778
9
2 Number Systems and Binary Arithmetic

Exercises in a nutshell

FADE,FEDE 16= ???2


3210,9816= ???2
1011,0111 10012=???16
11101,0110012 =???16

FADE,FEDE 16=1111 1010 1101 1110, 1111 1110 1101 11102


3210,9816= 0011 0010 0001 0000, 1001 10002
1011,0111 10012=B,7916
11101,0110012 =1D,6416

10
2 Number Systems and Binary Arithmetic

2.3 Representation of Negative Numbers

Decimal Binary
Number Number
● Representation of signs (negative numbers) system System
in binary numbers:
+ 0
(only „0“ and „1“ are available) - 1

11
2 Number Systems and Binary Arithmetic

One's Complement Code


● The negative counterpart of a positive number is obtained by reversing all bits.
„0“ → „1“ and „1“ → „0“

Example: 2610
(+) 0↓ 1

1

0

1

0

=

( -) 1 0 0 1 0 1 = -2610

● Complementing by subtraction 2n −1 3110


1 1 1 1 1 =
1 1 0 1 0 = 2610
¿1 n
C Z =2 −1−Z 0 0 1 0 1 = 510

12
2 Number Systems and Binary Arithmetic

Two's Complement Code


● The two's complement is used in computers for representation of negative numbers.
● Method:
The negative counterpart of a positive number is obtained by reversing all bits.
„0“ → „1“ and „1“ → „0“ (as done for the one's complement)
After reversing each bit: Adding of one bit to it

Example: 0 1 1 0 1 0 = 3110
↓ ↓ ↓ ↓ ↓ ↓
1 0 0 1 0 1 = One's complement

+1 1 0 0 1 1 0 = Two's complement

● Complementing by subtraction

C ¿ 2  Z = 2n −1−Z 1=2n −Z 1 0 0 0 0 0 = 3210


1 0 1-1 0 -1 1 0 = 2610
0 0 0 1 1 0 = 610
13
2.5   Binary Arithmetic

2.5.1  Binary Addition
a b sum carry
Truth table for  0 0 0 0
0+0=0
0+1=1 the addition  0 1 1 0
1+0=1 of two single bits 1 0 1 0
1 + 1 = 0 + Carry (half adder) 1 1 0 1

Addition of a 4­bit vector Full adder truth table and circuit

c4 c3 c2 c1 carry CIN A B S CO
0 0 0 0 0
0 0 1 1 0
a3 a2 a1 a0
+
0 1 0 1 0
0 1 1 0 1
b3 b2 b1 b0 1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
s4 s3 s2 s1 s0 sum
1 1 1 1 1

14
2.5   Binary Arithmetic

Exercises in a nutshell

1101 111101 1 1 0 0, 1 1
+ 100 + 1001 + 1 1 1, 0 1
????? ????? ?????

1101 111101 1 1 0 0, 1 1
+ 100 + 1001 + 1 1 1, 0 1
10001 1000110 10100,00
15
2.5   Binary Arithmetic

2.5.2  Binary Subtraction
M(inuend) S(ubtrahend) D(ifference) B(orrow)
0–0=0 0 0 0 0
1–0=1 0 1 1 0
1–1=0 1 0 1 0
0–1=1 + borrow 1 1 0 1

Truth table for the subtraction 
Half subtractor circuit (no borrow bit input)
of two single bits

Subtraction of a 4­bit vector Or adding two's complement of the subtrahend

B4 B3 B2 B1 Borrow c4 c3 c2 c1 carry
M3 M2 M1 M0 a3 a2 a1 a0

­ S3 S2 S1 S0 + b*3 b*2 b*1 b*0

D 4 D3 D2 D 1 D0 Difference D4 D3 D2 D1 D0 Difference
16
2.5   Binary Arithmetic

2.5.3  Binary Multiplication

a b Product
Truth table for the multiplication
0 0 0
0 1 0
of two single bits.
1 0 0 Hint: rules are identical to decimal number system
1 1 1

b3 b2 b1 b0 x a3 a2 a1 a0

a0b3 a0b2 a0b1 a0b0

a1b3 a1b2 a1b1 a1b0


a2b3 a2b2 a2b1 a2b0

+ a3b3 a3b2 a3b1 a3b0


P7 P6 P5 P4 P3 P2 P1 P0

17
2.6   Codes

Decimal Binary Octal Hexadecimal


0 0000 00 0 The purpose of using
Octal an Hexadecimal
1 0001 01 1
codes is to represent the
2 0010 02 2 binary code more readable
3 0011 03 3 and compact for humans.
4 0100 04 4 ● Octal code needs 3 bits
5 0101 05 5
6 0110 06 6 ● Hex-Code needs 4 bits
7 0111 07 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F 18
2.6   Codes

Representation of Decimal Numbers

19
2.6   Codes

Representation with Codes     →    BCD­Code

BCD (binary coded decimal) or 8­4­2­1 Code

20
Representation with Codes     →    Gray­Code

21
2.6   Codes

Decimal BCD Gray Excess-3


8421 Code Code
0 0000 0000 0011
1 0001 0001 0100
● BCD (binary Coded Decimal
2 0010 0011 0101 ● Gray Code
3 0011 0010 0110 differs only by one bit
4 0100 0110 0111 adjacent codewods
5 0101 0111 1000 ● Excess-3
6 0110 0101 1001 adding 3d = 112 to
7 0111 0100 1010 the numbers
8 1000 1100 1011 → self complementing code
9 1001 1101 1100 ● Further codes:
10 0001 0000 1111 1101 ASCII, BC 2421 ...
11 0001 0001 1110 1110
12 0001 0010 1010 Not used
13 0001 0011 1011 Not used
14 0001 0100 1001 Not used
22
15 0001 0101 1000 Not used

You might also like