BLE 201
DIGITAL ELECTRONICS
COMPLEMENTS
The r’s Complement
The (r −1)’s Complement
Complements
➢ Complements are used in digital computers for simplifying the subtraction operation
and for logical manipulations.
➢ There are two types of complements for each system:
❖ the r's complement and
❖ the (r −1)'s complement.
➢ When the value of the base is substituted, the two types receive the names 2's and 1's
Complement for binary numbers, or 10's and 9's complement for decimal numbers.
The r’s Complement
➢ Given a positive number N in base r with an integer part of n digits, the r's complement of N is
defined as rn - N for N ≠ 0 and 0 for N = 0.
➢ Example:
The 10's complement of (52520)10 is 105 −52520 = 47480.
The 10's complement of (0.3267)10 is 1-0.3267 = 0.6733.
No integer part, so 10n = 100 = 1
➢ The 2's complement of (101100), is (26)10 − (101100)2 = (1000000 − 101100)2 = 010100.
➢ The 2's complement of (0.0110)2 is (1 − 0.0110)2 = 0.1010.
The (r −1)’s Complement
➢ Given a positive number N in base r with an integer part of n digits and a fraction part of m
digits, the (r −1)’s complement of N is defined as rn − r−m − N.
➢ Examples :
The 9's complement of (52520)10 is (105 −1− 52520) = 99999 − 52520 = 47479
The 9's complement of (0.3267)10 is (1−10−4 − 0.3267) = 0.9999 − 0.3267 = 0.6732.
The 9's complement of (25.639)10 is (102 −10−3 −25.639) = 99.999 − 25.639 = 74.360.
➢ The 1's complement of (101100)2 is (26 − 1) − (101100) = (111111 − 101100)2 = 010011
The 1’s complement of (0.0110)2,is (1−2−4)10− (0.0110)2 = (0.1111 − 0.0110)2 = 0.1001
Subtraction with r’s complement
➢ The subtraction of two positive numbers (M-N ), both of base r, may be done as follow:
1. Add the minuend M to the r's complement of the subtrahend 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.
EXAMPLE: Using 10's complement, subtract 72532 − 3250.
M = 72532
N = 03250 72532
10's complement of N = 96750 + 96750
end carry →1 69282
answer: 69282
EXAMPLE : Subtract: (3250 −72532)10
M = 03250
N = 72532 03250
10's complement of N = 27468 +27468
no carry 30718
answer: −69282 = −(10's complement of 30718)
EXAMPLE : Use 2’s complement to perform M −N with the given binary numbers.
(a) M = 1010100
N = 1000100 1010100
+ 0111100
2’s complement of N = 0111100 end carry → 1 0010000
answer: 10000
(b) M =1000100
N = 1010100
1000100
+ 0101100
2's complement of N = 0101100 no carry 1110000
answer: − 10000 = − (2's complement of 1110000)
Subtraction using (r −1)’s complement
➢ The subtraction of M −N, both positive numbers in base r, may be calculated in the following
manner:
1. Add the minuend M to the (r −1)'s complement of the subtrahend 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.
EXAMPLE: Using 9's complement, subtract 72532 − 3250. 72532
M = 72532 + 96749
N = 03250 End-around carry →1 69281
9's complement of N = 96749 + 1
69282
answer: 69282
EXAMPLE : Subtract: (3250 −72532)10
M = 03250
N = 72532 03250
9's complement of N = 27467 +27467
no carry 30717
answer: −69282 = −(9's complement of 30717)
EXAMPLE : Use 1’s complement to perform M −N with the given binary numbers.
(a) M = 1010100 1010100
N = 1000100 + 0111011
end-around carry → 1 0001111
1’s complement of N = 0111011 + 1
0010000
answer: 10000
(b) M =1000100
N = 1010100
1000100
+ 0101011
1's complement of N = 0101011 no carry 1101111
answer: − 10000 = − (1's complement of 1101111)
Signed Numbers
➢ Digital systems, such as the computer, must be able to handle both positive and negative
numbers.
➢ A signed binary number consists of both sign and magnitude information.
➢ The most significant bit (MSB) is the sign bit and treating the remaining bits as magnitude bits.
➢ There are three forms in which signed integer number can be represented in binary.
❖ Sign magnitude form
❖ 1’s Complement form
❖ 2’s Complement form
Sign Magnitude form
➢ Signed-magnitude form
❖ The sign bit is the left-most bit in a signed binary number
❖ A 0 sign bit indicates a positive magnitude
❖ A 1 sign bit indicates a negative magnitude
Sign bit Magnitude bits
Example: +25 = 00011001
−25 = 10011001
1’s Complement Form
➢ 1’s complement form
❖ A negative number is the 1’s complement of the corresponding positive number.
❖ Positive numbers in 1’s complement form are represented the same way as the positive
signed magnitude numbers.
➢ Example: +25 = 00011001
❖ Using 8 bits, decimal number −25 is expressed as the 1’s complement of +25 (00011001) as
−25 = 11100110
2’s Complement Form
➢ 2’s complement form
❖ A negative number is the 2’s complement of the corresponding positive number.
❖ Positive numbers in 2’s complement form are represented the same way as in the signed
magnitude and 1’s complement form.
➢ Example: +25 = 00011001
❖ Using 8 bits, decimal number −25 is expressed as the 2’s complement of +25 (00011001) as
−25 = 11100111
The Decimal Value of Signed Numbers
➢ Sign-Magnitude
❖ Decimal values of positive and negative numbers in the sign-magnitude form are determined
by summing the weights in all the magnitude bit positions where there are 1s and ignoring
those positions where there are zeros.
❖ The sign is determined by examination of the sign bit
Example:
➢ 1’s Complement
❖ Decimal values of positive numbers in the 1’s complement form are determined by summing
the weights in all bit positions where there are 1s and ignoring those positions where
there are zeros.
❖ Decimal values of negative numbers are determined by assigning a negative value to the weight
of the sign bit, summing all the weights where there are 1s, and adding 1 to the result.
Example:
➢ 2’s Complement
❖ Decimal values of positive and negative numbers in the 2’s complement form are determined
by summing the weights in all bit positions where there are 1s and ignoring those positions
where there are zeros.
❖ The weight of the sign bit in a negative number is given a negative value.
Example:
Range of Signed Integer Numbers
➢ 8-bit grouping is common in most computers and has been given the special name byte.
➢ With one byte or eight bits, you can represent 256 different numbers.
➢ With two bytes or sixteen bits, you can represent 65,536 different numbers.
➢ The formula for finding the number of different combinations of n bits is
Total combinations = 2n
➢ For signed magnitude and 1’s complement signed numbers, the range of values for n-bit
numbers is
Range = −(2n−1 −1) to +(2n−1 − 1) and ± 0
➢ For 2’s complement signed numbers, the range of values for n-bit numbers is
Range = −(2n−1) to +(2n−1 − 1)
Note: In each case there is one sign bit and n−1 magnitude bits.