Lecture9 ESC201
Lecture9 ESC201
1
Complement of a binary number
1’s complement
Binary system:
2’s complement
0110010
2's complement of 1010 = 1's complement of 1010+1 = 0110
001110
1011 → 0101
101101100 → 010010100
Advantages of using 2’s complement
x1 S
Adder
x2 CY
Adder
2's Complement CY Sign
x2
Sign = 0 for psotive numbers
= 1 for negative numbers
2 N − x2 (CY , S ) = x1 + 2 N − x2
Note that carry will be there only if x1 – x2 is positive as 2N is N+1 bits (1 followed by N zeros)
Advantages of using 2’s complement
Adder
2's Complement CY Sign
x2
Sign = 0 for psotive numbers
= 1 for negative numbers
2 N − x2 (CY , S ) = x1 + 2 N − x2
Note that carry will be there only if x1 – x2 is positive as 2N is N+1 bits (1 followed by N zeros)
A zero carry implies a negative number whose magnitude (x2 – x1) can be found as follows:
S = x1 + 2 N − x2
2'scomplement of S = 2 N − ( x1 + 2 N − x2 ) = x2 − x1
Example
10 0100
0100
S
x1=1010 Y = S if Sign = 0
Y = 2's Complement of S if Sign = 1 Y
Adder
2's Complement CY Sign
x2=0110
Sign = 0 for psotive numbers 0
1
6 = 1 for negative numbers
1010
1010
+1010
10100
Example
6 1100
0100
S
x1=0110 Y = S if Sign = 0
Y = 2's Complement of S if Sign = 1 Y
Adder
2's Complement CY Sign
x2=1010
Sign = 0 for psotive numbers 1
0
10 = 1 for negative numbers
0110
0110
+0110
1100
It makes sense to use adder as a subtractor as well provided additional circuit required for
carrying out 2’s complement is simple
Subtraction using 10’s complement
5
x1,x2: N digit numbers 5
S
x1 Y = S if Sign = 0
Y = 10's Complement of S if Sign = 1 Y
8
Adder
10's Complement CY Sign
x2 1
Sign = 0 for psotive numbers 0
3
10-3=7 = 1 for negative numbers
This way of subtraction would make sense only if subtracting a number x2 from 10N is much
simpler than directly subtracting it directly from x1
Representing positive and negative binary numbers
One extra bit is required to carry sign information. Sign bit = 0 represents positive number
and Sign bit = 1 represents negative number
decimal Signed decimal Signed 1’s decimal Signed 2’s
Magnitude complement complement
0 0000 0 0000 0 0000
1 0001 1 0001 1 0001
2 0010 2 0010 2 0010
3 0011 3 0011 3 0011
4 0100 4 0100 4 0100
5 0101 5 0101 5 0101
6 0110 6 0110 6 0110
7 0111 7 0111 7 0111
-0 1000 -0 1111 -1 1111
-1 1001 -1 1110 -2 1110
-2 1010 -2 1101 -3 1101
-3 1011 -3 1100 -4 1100
-4 1100 -4 1011 -5 1011
-5 1101 -5 1010 -6 1010
-6 1110 -6 1001 -7 1001
-7 1111 -7 1000
If we represent numbers in 2’s complement form carrying out subtraction is same as addition
Adder
2's Complement CY Sign
x2
Sign = 0 for psotive numbers
= 1 for negative numbers
S Answer is in 2’s
x1 complement form
Adder
x2 CY
Adder
x2 CY
0101 0101
+5 +0010 +5 +1110
+2 -2
+7 0111 +3 0011
1011 1011
-5 +0010 -5 +1110
+2 -2
-3 1101 -7 1001
Basic operations:
True
AND: y = x1. x 2 Yes
1
High voltage
Y is 1 if and only if both x1 and x2 are 1, otherwise zero
x1 x2 y
0 0 0
Truth Table
0 1 0
1 0 0
1 1 1
Basic operations:
OR: y = x1 + x 2
x1 x2 y
0 0 0
0 1 1
1 0 1
1 1 1
x y
NOT: y = x
0 1
1 0