04 Week02 1&2Complement
04 Week02 1&2Complement
Complement
Complements
• Subtraction of numbers requires a different algorithm
than addition.
• Adding a complement of a number is equivalent to
subtraction.
• We will discuss two complements:
Diminished Radix Complement
Radix Complement
• Subtraction will be accomplished by adding a
complement.
Diminished Radix Complement
Given a number N in Base r having n digits, the (r-1)'s
complement (called the Diminished Radix Complement) is
defined as:
(rn - 1) - N
Example:
For r = 10, N = 123410, n = 4 (4 digits),we have:
(rn - 1) = 10,000 -1 = 999910
The 9's complement of 123410 is then:
999910 - 123410 = 876510
Binary 1's Complement
For r = 2, N = 01110011 2, n = 8 (8 digits), we have:
(rn - 1) = 256 -1 = 25510 or 111111112
The 1's complement of 011100112 is then:
11111111 2
- 01110011 2
----------------
100011002
NOTE: Since the 2n-1 factor consists of all 1's and
since 1 - 0= 1 and 1 - 1 = 0, forming the one's
complement consists of complementing each
individual bit.
Radix Complement
Given a number N in Base r having n digits, the r's
complement (called the Radix Complement) is defined as:
rn - N for N 0 and
0 for N = 0
Note that the Radix Complement is obtained by adding 1
to the Diminished Radix Complement.
Example:
For r = 10, N = 123410, n = 4 (4 digits), we have:
rn = 10,00010
The 10's complement of 123410 is then
10,00010 - 123410 = 876610 or 8765 + 1 (9's complement plus 1)
Binary 2's Complement
For r = 2, N = 011100112, n = 8 (8 digits), we have:
This 0110100111100
becomes 1001011000100
This 1000000000000
becomes 1000000000000
Subtraction with Radix
Complements
Subtract two n-digit, unsigned numbers M N,
in base r as follows:
1. Add the minuend M to the r's complement of the
subtrahend N to perform:
M + (r - N) = M N + r
n n
1010100
2). Add the two: 0111101
(+) -------------
1 0010001 (a carry )
If the end carry does not occur, the result is negative and
we can use the 1's complement to represent the negative
result.
1’s Complement Subtraction
Use 1's complement to compute 1010100 - 1000011
1). Form 1's complement of 1000011: 1000011
0111100
2). Add the two: 1010100
0111100
(+) -------------
10010000 (a carry)
3). Add carry, end around (+) 0000001
-------------
0010001
Ans. = 0010001
1’s Complement Subtraction
Use 1's complement for computing 1000011 - 1010100
1). Form 1's complement of 1010100: 1010100
0101011
1000011
2). Add the two:
0101011
(+) -------------
1101110 (no carry)
one S S S S