Complements, Binary Arithmetic
Complements, Binary Arithmetic
Complements
• Complements are used in digital computers for simplifying the
subtraction operation and for logical manipulations. There are two
types of complements for each number system of base-r: the r’s
complement and the (r – 1)’s complement. When we deal with a
binary system the value of r is 2 and hence the complements are 2’s
and 1’s complements. Similarly for a decimal system the value of r is
10 and we get 10’s and 9’s complements. With the same logic if the
number system is octal we get 8’s and 7’s complement, while it is 16’s
and 15’s complements for hexadecimal system.
The r’s Complement
1. If a positive number N is given in base r with an integer part of n
digits, the r’s complement of N is given as rn–N for N != 0 and 0 for
N = 0.
2. The 10’s complement of (23450)10 is 105 – 23450 = 76550.
3. The number of digits in the number is n = 5.
4. The 10’s complement of (0.3245)10 is 100 – 0.3245 = 0.6755.
5. Since the number of digits in the integer part of the number is n = 0,
we have 100 = 1.
6. The 10’s complement of (23.324)10 is 102 – 23.324 = 76.676.
The number of digits in the integer part of the number is n = 2.
Now if we consider a binary system, then r = 2.
The 2’s complement of (10110)2 is (25)10–(10110)2 = (100000 – 10110)2 = 01010.
The 2’s complement of (0.1011)2 is (20)10–(0.1011)2 = (1 – 0.1011)2 = 0.0101.
= B5D016.
• From the above examples, it is clear that to find the 10’s complement of a
decimal number all of the bits until the first significant 0 is left unchanged
and the first nonzero least-significant digit is subtracted from 10 and the rest
of the higher significant digits are subtracted from 9. With a similar
reasoning, the 2’s complement of a binary number can be obtained by
leaving all of the least significant zeros and the first nonzero digit unchanged,
and then replacing 1’s with 0’s and 0’s with 1’s. Similarly the 8’s complement
of an octal number can be obtained by keeping all the bits until the first
significant 0 is unchanged, and the first non zero least significant digit is
subtracted from 8 and the rest of the higher significant digits are subtracted
from 7. Similarly, the 16’s complement of a hexadecimal number can be
obtained by keeping all the bits until the first significant 0 is unchanged, and
the first nonzero least-significant digit is subtracted from 16 and the rest of
the higher significant digits are subtracted from 15. Since r’s complement is a
general term, r can take any value e.g., r = 11. Then we will have 11’s
complement for r’s complement case and 10’s complement for (r – 1)’s
complement case.
•
The (r–1)’s Complement
1. If a positive number N is given in base r with an integer part of n
digits and a fraction part of m digits, then the (r – 1)’s complement
of N is given as (rn – r–m– N) for N 0 and 0 for N = 0. The following
examples will clarify the definition.
2. The 9’s complement of (23450)10 is 105 – 100 – 23450 = 76549.
Since there is no fraction part, 10–m = 100 = 1.
3. The 9’s complement of (0.3245)10 is 100 – 10–4 – 0.3245 = 0.6754.
Since there is no integer part, 10n = 100 = 1.
4. The 9’s complement of (23.324)10 is 102 – 10–3 – 23.324 = 76.675.
Now if we consider a binary system, then r = 2, i.e., (r – 1) = 1.
The 1’s complement of (10110)2 is (25–1)10 – (10110)2 = 01001.
The 1’s complement of (0.1011)2 is (1–2–4)10 – (0.1011)2 = 0.0100.
Now, the decimal number has to be changed in the number system of base 11.
Division Quotient Generated remainder
642/11 58 4
58/11 5 3
5/11 0 5
0 0 0 0 0
0 1 1 0 1
1 0 1 0 1
1 1 0 1 10
Binary Subtraction
The rules of binary subtraction are given in Table 1.2.
Minuend Subtrahend Difference Borrow
0 0 0 0
0 1 1 1
1 0 1 0
1 1 0 0
• Binary subtraction is also carried out in a similar method
to decimal subtraction. The subtraction is carried out
from the LSB and proceeds to the higher significant bits.
When borrow is 1, as in the second row, this is to be
subtracted from the next higher binary bit as it is
performed in decimal subtraction.
• Actually, the subtraction between two numbers can be
performed in three ways, viz.
– the direct method,
– the r’s complement method, and
– the (r – 1)’s complement method.
Subtraction Using the Direct Method
0 0 0
0 1 0
1 0 0
1 1 1
Binary Division
• Binary division follows the same procedure as decimal
division. The rules regarding binary division are listed in
Table 1.4.