1. 3/28/2012
1
Digital Logic & Design
Dr. Sajjad Ahmed Nadeem
Department of Computer Science & IT
University of Azad Jammu & Kashmir
Muzaffarabad
Module 02_01
Complements.
The (r-1)’s Complement.
The r’s Complement.
Subtraction with Complements.
2. 3/28/2012
2
Complements (1)
Used in digital computers for
◦ simplifying the subtraction operation
◦ logical manipulations.
There are two types of complements for each base-r
system:
1. The (r – 1)’s Complement (Diminished radix complement).
2. The r’s Complement (Radix complement).
For Decimal numbers we have 9’s and 10’s complement
For Binary numbers we have 1’s and 2’s complement
Complements (2)
Complements of numbers with fractions
1. Remove the radix point
2. Obtain the complement
3. Return the radix point to its position
3. 3/28/2012
3
The (r – 1)’s Complement (1)
Let X be a positive number in base r with n
digits, the (r – 1)’s complement of X is defined
as
(rⁿ - 1) – X
For r=10, it is called 9’s complement and
is given by (10ⁿ - 1) – X
For r=2, it is called 1’s complement and is
given by (2ⁿ - 1) – X
The (r – 1)’s Complement (2)
The 9’s complement of (52520)10 is
{(105 – 1) – 52520} = 99999 – 52520 = 47479.
The 9’s complement of (0.3267)10 is
{(104 – 1) – 3267} = 9999 – 3267 = 6732.
(Answer is 0.6732.)
The 9’s complement of (25.639)10 is
(105– 1– 25639) = 99999 – 25639 = 74360.
(Answer is 74.360.)
4. 3/28/2012
4
The (r – 1)’s Complement (3)
The 1’s complement of (101100)2 is
(26 – 1) 10 – (101100)2 = (111111 – 101100)2 =
010011.
The 1’s complement of (0.0110)2 is
(24 – 1)10 – (0110)2 = (1111 – 0110)2 = 1001.
(Answer is 0.1001)
The 1’s complement of (100.0110)2 is
(27 – 1)10 – (1000110)2 = (1111111 –
1000110)2 = 0111001.
(Answer is 011.1001)
The (r – 1)’s Complement (4)
The 9’s complement of a decimal number
is formed simply by subtracting every digit
from 9.
The 1’s complement of a binary number is
simpler to form: the 1’s are changed to 0’s
and 0’s to 1’s.
5. 3/28/2012
5
The r’s Complement (1)
Let X be a positive number in base r with n
digits, the r’s complement of X is defined as
rⁿ – X for X ≠ 0
0 for X = 0
For r=10, it is called 10’s complement and
is given by 10ⁿ – X = (10ⁿ – 1) – X + 1
For r=2, it is called 2’s complement and is
given by 2ⁿ – X = (2ⁿ – 1) – X + 1
The r’s Complement (1)
The 10’s complement of (52520)10 is
(105 – 1) – 52520 + 1 = 47480.
(The number of digits in the number is n=5.)
The 10’s complement of (0.3267)10 is
(104 – 1) – 3267 + 1 = 6733
(Answer is 0.6733)
The 10’s complement of (25.639)10 is
(105 – 1) – 25639 + 1= 74361
(Answer is 74.361)
6. 3/28/2012
6
The r’s Complement (2)
The 2’s Complement of (101100)2 is
{(26 – 1)10 – (101100)2 }+ 1
= (111111 – 101100)+1
= 010100.
The 2’s Complement of (0.0110)2 is
{(24 – 1)10 – (0110)2 }+ 1
= 1010.
(Answer is 0.1010)
The r’s Complement (3)
10’s complement can be formed by
◦ leaving all least significant zeros unchanged and
◦ then subtracting the first non-zero least significant
digit from 10, and
◦ then subtracting all other higher significant digits from
9.
The 2’s Complement can be formed by
◦ leaving all least significant zeros and first non zero
digit unchanged, and
◦ then replacing 1’s by 0’s and 0’s by 1’s in all other
higher significant digits.
7. 3/28/2012
7
Complement of Complement
The complement of complement restores
the number to its original value.
The r’s complement of N is rⁿ - N.
Therefore, the complement of (rⁿ - N) is
rⁿ - (rⁿ - N)
= N
Subtraction with r’s compliment (1)
The subtraction of two positive numbers (M – N), both
of base r, may be done as follows.
1. Add the minuend M to the r’s complement of
subtrahend N.
M – N =M+ r’s complement (N)
2. Inspect the result obtained in step 1 for an end carry:
(a) If an end carry occurs discard it.
(b) If an end carry does not occur, take the r’s
complement of the number obtained in step 1, and
place a negative sign in front.
8. 3/28/2012
8
Subtraction with r’s compliment (2)
Using 10’s complement,subtract 72532 – 3250.
M = 72532 , N = 03250.
10’s complement of subtrahend N = 96750.
Step 1: 72532
+ 96750
End Carry 1 69282
Step 2, discard carry.
Answer = 69282.
Subtraction with r’s compliment (3)
Subtract: (3250 – 72532)10
M = 03250,N = 72532.
10’s complement of N = 27468.
Step 1: 03250
+ 27468
30718 (No End Carry)
Step 2:Answer = - (10’s complement of 30718)
Answer = - 69282
9. 3/28/2012
9
Subtraction with r’s compliment (4)
Using 2’s complement, subtract 1010100 –
1000100.
M = 1010100,N = 1000100.
2’s complement of N = 0111100
Step 1: 1010100
+ 0111100
End Carry 1 0010000
Step 2: Discard Carry.
Answer = 0010000
Subtraction with r’s compliment (5)
Using 2’s complement, subtract 1000100 –
1010100.
M = 1000100,N = 1010100.
2’s complement of N = 0101100
Step 1: 1000100
+ 0101100
No Carry 1110000
Step 2:Answer = - (2’s complement of 1110000)
Answer = - 0010000
10. 3/28/2012
10
Subtraction with (r – 1)’s compliment (1)
The procedure for subtraction with the (r – 1)’s
complement is exactly the same as the one used with r’s
compliment except for one variation, called “end-round
carry”.
The subtraction of two positive numbers (M – N), both of
base r, may be done as follows.
1. Add the minuend M to the (r – 1)’s complement of the
subtrahend N.
M – N =M+ (r – 1)’s complement (N)
2. Inspect the result obtained in step 1 for an End carry.
(a) If an end carry occurs, add 1 to the least significant
digit ( end-around carry).
(b) If an end carry does not occur, take the (r – 1)’s
complement of the number obtained in step 1 and place
a negative sign in front.
Using 9’s complement, subtract 72532 – 3250.
M = 72532 , N = 03250.
9’s complement of subtrahend N = 96749.
Step 1: 72532
+ 96749
End-around Carry 1 69281
Step 2,add end around carry. + 1
Answer = 69282
Subtraction with (r – 1)’s compliment (2)
11. 3/28/2012
11
Subtract: (3250 – 72532)10
M = 03250,N = 72532.
9’s complement of N = 27467.
Step 1: 03250
+ 27467
30717 (No End Carry)
Step 2:Answer = - (9’s complement of 30717)
Answer = - 69282
Subtraction with (r – 1)’s compliment (3)
Using 1’s complement, subtract 1010100 –
1000100.
M = 1010100,N = 1000100.
1’s complement of N = 0111011
Step 1: 1010100
+ 0111011
End Carry 1 0001111
Step 2 + 1
Answer = 0010000
Subtraction with (r – 1)’s compliment (4)
12. 3/28/2012
12
Using 1’s complement, subtract 1000100 –
1010100.
M = 1000100,N = 1010100.
1’s complement of N = 0101011
Step 1: 1000100
+ 0101011
No Carry 1101111
Step 2:Answer = - (1’s complement of 1101111)
Answer = - 10000
Subtraction with (r – 1)’s compliment (5)
Signed Binary Numbers (1)
We have one way to represent a positive number
(say +9)
Three ways to represent a negative numbers (say -9)
Sign Bit
◦ Signed-magnitude representation 1 0001001
◦ Signed-1’s complement representation 1 1110110
◦ Signed-2’s complement representation 1 1110111
13. 3/28/2012
13
Signed Binary Numbers (2)
Signed Binary Numbers-Addition
Addition of two numbers in signed magnitude system
follow the same rules of ordinary arithmatic.
The addition of two signed binary numbers
◦ Use binary representation of the numbers and add them
◦ In case of negative number, add the 2’s complement of the negative
number to the positive number alongwith sign bits
◦ Add the 2’s complement of the negative numbers
◦ A carry out of the sign bit position is discarded
◦ If the sum obtained is in negative it is automatically in 2’s
complement form.
14. 3/28/2012
14
Signed Binary Numbers-Subtraction
Take the 2’s complement of the subtrahed (including the
sign bit)
Add the obtained 2’s complement to the minuend
(including the sign bit).
A carry out of sign bit is discarded
Assignment
r’s complement for octal & hexadecimal
(r-1)’s complement for octal &
hexadecimal
Comparison between 1’s and 2’s
Complement.