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
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 not.equal 0 and 0 for N = 0. The following examples will clarify the defi nition.
The 10’s complement of (23450)10 is 105 – 23450 = 76550.
The number of digits in the number is n = 5.
The 10’s complement of (0.3245)10 is 100 – 0.3245 = 0.6755.
Since the number of digits in the integer part of the number is n = 0, we have 100 = 1.
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)–(10110)2 = (100000 – 10110)2 = 01010.
The 2’s complement of (0.1011)2 is (20)–(0.1011)2 = (1 – 0.1011)2 = 0.0101.
Now if we consider an octal system, then r = 8.
The 8’s complement of (2450)8 is (84) – (2450)8 = (10000)8 – (2450)8 = (5330)8
Now if we consider a hexadecimal system, then r = 16.
The 16’s complement of (4A30)16 is (164) – (4A30)16 = (10000)16 – (4A30)16 = 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 signifi cant zeros and the fi rst 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 nonzero least significant digit is subtracted from 8 and the rest of the higher signifi cant 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
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 not.equal 0 and 0 for N = 0. The following examples will clarify the definition.
The 9’s complement of (23450)10 is 105 – 100 – 23450 = 76549.
Since there is no fraction part, 10–m = 100 = 1.
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.
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 if we consider an octal system, then r = 8, i.e., (r – 1) = 7.
The 7’s complement of (2350)8 is 84 – 80 – 23508 = 54278
The 15’s complement of (A3E4)16 is 164 – 160 – A3E416 = 5C1B16
From the above examples, it is clear that to fi nd the 9’s complement of a decimal number each of the digits can be separately subtracted from 9. The 1’s complement of a binary number can be obtained by changing 1s into 0s and 0s into 1s. Similarly, to find the 7’s complement of a decimal number each of the digits can be separately subtracted from 7. Again, to fi nd the 15’s complement of a decimal number each of the digits can be separately subtracted from 15.
BINARY ARITHMETIC Binary Subtraction
We are very familiar with different arithmetic operations, viz. addition, subtraction, multiplication, and division in a decimal system. Now we want to fi nd out how those same operations may be performed in a binary system, where only two digits, viz. 0 and 1 exist.
Binary Addition
The rules of binary addition are given in Table below.
The procedure of adding two binary numbers is same as that of two decimal numbers. Addition is carried out from the LSB and it proceeds to higher significant bits, adding the carry resulting from the addition of two previous bits each time.
EXAMPLE: Add the binary numbers: (a) 1010 and 1101 (b) 0110 and 1111
Binary Subtraction
The rules of binary subtraction are given in Table below.
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.
(i) the direct method,
(ii) the r’s complement method, and
(iii) the (r – 1)’s complement method.
Subtraction Using the Direct Method
The direct method of subtraction uses the concept of borrow. In this method, we borrow a 1 from a higher signifi cant position when the minuend digit is smaller than the corresponding subtrahend digit.
Example 1. Using the direct method to perform the subtraction 1001 – 1000.
Example 2. Using the direct method to perform the subtraction 1000 – 1001.
When the minuend is smaller than the subtrahend the result of subtraction is negative and in the direct method the result obtained is in 2’s complement form. So to get back the actual result we have to perform the 2’s complement again on the result thus obtained.
Digital circuits perform binary arithmetic operations. It is possible to use the circuits designed for binary addition to perform binary subtraction. Only we have to change the problem of subtraction into an equivalent addition problem. This can be done if we make use of 1’s and 2’s complement form of the binary numbers as we have already discussed.
Subtraction Using 1’s Complement
Binary subtraction can be performed by adding the 1’s complement of the subtrahend to the minuend. If a carry is generated, remove the carry, add it to the result. This carry is called the end-around carry. Now if the subtrahend is larger than the minuend, then no carry is
generated. The answer obtained is 1’s complement of the true result and opposite in sign.
Example 1. Subtract 1001 from 1101 using the 1’s complement method. Also subtract using the direct method and compare.
Example 2. Subtract (1100)2 from (1001)2 using the 1’s complement method. Also subtract using the direct method and compare.
In the direct method, whenever a larger number is subtracted from a smaller number, the result obtained is in 2’s complement form and opposite in sign. To get the true result we have to discard the carry and make the 2’s complement of the result obtained and put a negative sign before the result.
In the 1’s complement subtraction, no carry is obtained and the result obtained is in 1’s complement form. To get the true result we have to make the 1’s complement of the result obtained and put a negative sign before the result.
Subtraction Using 2’s Complement
Binary subtraction can be performed by adding the 2’s complement of the subtrahend to the minuend. If a carry is generated, discard the carry. Now if the subtrahend is larger than the minuend, then no carry is generated. The answer obtained is in 2’s complement and is negative. To get a true answer take the 2’s complement of the number and change the sign. The advantage of the 2’s complement method is that the end-around carry operation present in the 1’s complement method is not present here.
Example. Subtract 0111 from 1101 using the 2’s complement method. Also subtract using the direct method and compare.
Example. Subtract 1010 from 1001 using the 1’s complement method. Also subtract using the direct method and compare.
In the direct method, whenever a larger number is subtracted from a smaller number, the result obtained is in 2’s complement form and opposite in sign. To get the true result we have to discard the carry and make the 2’s complement of the result obtained and put
a negative sign before the result.
In the 2’s complement subtraction, no carry is obtained and the result obtained is in 2’s complement form. To get the true result we have to make the 2’s complement of the result obtained and put a negative sign before the result.
PROBLEM. Represent (–19) in
(a) Sign-magnitude,
(b) one’s complement, and
(c) two’s complement representation.
Solution.
The minimum number of bits required to represent (+19)10 in signed number format is six.
Therefore, (+19)10 = (010011)2
Then, (–19)10 is represented by
(a) 110011 in sign-magnitude representation.
(b) 101100 in 1’s complement representation.
(c) 101101 in 2’s complement representation.
9’s AND 10’s COMPLEMENT ARITHMETIC
The 9’s complement of a decimal number can be found by subtracting each digit in the number from 9. The 10’s complement can be obtained by subtracting the LSB from 10 and the rest of each digit in the number from 9. The 9’s and 10’s complement of the decimal
digits 0 to 9 is shown in Table below.
The method of subtraction using 9’s complement method is the same as 1’s complement method in a binary system. Here also the carry obtained is added to the result to get the true result. And as in the previous cases, if the minuend is larger than the subtrahend, no carry
is obtained and the result is obtained in 9’s complement form. To get the true result we have to again get the 9’s complement of the result obtained and put a negative sign before it.
Similarly, the method of subtraction using 10’s complement method is the same as 2’s complement method in a binary system. Here also the carry obtained is discarded to get the true result. And as in the previous cases, if the minuend is larger than the subtrahend, no carry is obtained and the result is obtained in 10’s complement form. To get the true result we have to again get the 10’s complement of the result obtained and put a negative sign before it.
Subtraction Using 9’s Complement
Example 1. Subtract (358)10 from (592)10 using the 9’s complement method. Also subtract using the direct method and compare.
Example 2. Subtract (592)10 from (358)10 using the 9’s complement method. Also subtract using the direct method and compare.
Subtraction Using 10’s Complement
Example 1. Subtract (438)10 from (798)10 using the 10’s complement method. Also subtract using the direct method and compare.
Example 2. Subtract (798)10 from (438)10 using the 10’s complement method. Also subtract using the direct method and compare.
7’s AND 8’s COMPLEMENT ARITHMETIC
The 7’s complement of an octal number can be found by subtracting each digit in the number from 7. The 8’s complement can be obtained by subtracting the LSB from 8 and the rest of each digit in the number from 7. The 7’s and 8’s complement of the octal digits 0 to 7 is shown in Table below.
The method of subtraction using 7’s complement method is the same as 1’s complement method in binary system. Here also the carry obtained is added to the result to get the true result. And as in the previous cases, if the minuend is larger than the subtrahend, no carry is obtained and the result is obtained in 7’s complement form. To get the true result we have to again get the 7’s complement of the result obtained and put a negative sign before it.
Similarly, the method of subtraction using 8’s complement method is the same as 2’s complement method in a binary system. Here also the carry obtained is discarded to get the true result. And as in the previous cases, if the minuend is larger than the subtrahend, no carry
is obtained and the result is obtained in 8’s complement form. To get the true result we have to again get the 8’s complement of the result obtained and put a negative sign before it.
Subtraction Using 7’s Complement
Example 1. Subtract (372)8 from (453)8 using the 7’s complement method. Also subtract using the direct method and compare.
Example 2. Subtract (453)8 from (372)8 using the 7’s complement method. Also subtract using the direct method and compare.
In the direct method, whenever a larger number is subtracted from a smaller number, the result obtained is in 8’s complement form and opposite in sign. To get the true result we have to discard the carry and make the 8’s complement of the result obtained and put a negative sign before the result.
Subtraction Using 8’s Complement
Example 1. Subtract (256)8 from (461)8 using the 8’s complement method. Also subtract using the direct method and compare.
Example 2. Subtract (461)8 from (256)8 using the 8’s complement method. Also subtract using the direct method and compare.
In the direct method, whenever a larger number is subtracted from a smaller number, the result obtained is in 8’s complement form and opposite in sign. To get the true result we have to discard the carry and make the 8’s complement of the result obtained and put a negative sign before the result.
15’s AND 16’s COMPLEMENT ARITHMETIC
The 15’s complement of a hexadecimal number can be found by subtracting each digit in the number from 15. The 16’s complement can be obtained by subtracting the LSB from 16 and the rest of each digit in the number from 15. The 15’s and 16’s complement of the hexadecimal digits 0 to F is shown in Table below.
The method of subtraction using 15’s complement method is the same as 9’s complement method in a decimal system. Here also the carry obtained is added to the result to get the true result. And as in the previous cases, if the minuend is larger than the subtrahend, no carry is
obtained and the result is obtained in 15’s complement form. To get the true result we have to again get the 15’s complement of the result obtained and put a negative sign before it.
Similarly, the method of subtraction using 16’s complement method is the same as 10’s complement method in a decimal system. Here also the carry obtained is discarded to get the true result. And as in the previous cases, if the minuend is larger than the subtrahend, no carry is obtained and the result is obtained in 16’s complement form. To get the true result we have to again get the 16’s complement of the result obtained and put a negative sign before it.
Subtraction Using 15’s Complement
Example 1. Subtract (2B1)16 from (3A2)16 using the 15’s complement method. Also subtract using the direct method and compare.
Example 2. Subtract (3A2)16 from (2B1)16 using the 15’s complement method. Also subtract using the direct method and compare.
Subtraction Using 16’s Complement
Example 1. Subtract (1FA)16 from (2DC)16 using the 16’s complement method. Also subtract using the direct method and compare.
Example 2. Subtract (2DC)16 from (1FA)16 using the 16’s complement method. Also subtract using the direct method and compare.
BCD ADDITION
The only thing we want to mention here is that, in this code, each decimal digit from 1 to 9 is coded in 4-bit binary numbers. But with 4-bit binary sixteen different groups can be obtained, whereas we require only ten groups to write BCD code. The other six groups are called forbidden codes in BCD and they are invalid for BCD. BCD is a numerical code. Many applications require arithmetic operation. Addition is the most important of these because the other three operations, viz. subtraction, multiplication, and division, can be performed using addition.
There are certain rules to be followed in BCD addition as given below.
(i) First add the two numbers using normal rules for binary addition.
(ii) If the 4-bit sum is equal to or less than 9, it becomes a valid BCD number.
(iii) If the 4-bit sum is greater than 9, or if a carry-out of the group is generated, it is an invalid result. In such a case, add
(0110)2 or (6)10 to the 4-bit sum in order to skip the six invalid states and return the code to BCD. If a carry
results when 6 is added, add the carry to the next 4-bit group.
Example 1. Add the following BCD numbers: (a) 0111 and 1001 (b) 10010010 and 01011000.
BCD SUBTRACTION
In order to subtract any number from another number we have to add the 9’s complement of the subtrahend to the minuend. We can use the 10’s complement also to perform the subtraction operation.
Example 1. Carry out BCD subtraction for (893) – (478) using 9’s complement method.
Example 2. Carry out BCD subtraction for (768) – ( 274) using 10’s complement method.
Binary Multiplication / Binary Division
Binary multiplication and Binary Division is similar to decimal multiplication and division but much simpler than that. In a binary Multiplication system each partial product is either zero (multiplication by 0) or exactly the same as the multiplicand (multiplication by 1).
Example 1. Multiply the following binary numbers: (a) 0111 and 1101 (b) 1.011 and 10.01.
Example 2. Divide the following binary numbers: (a) 11001 and 101 (b) 11110 and 1001.
Homework-05 (1 week)
1) Show the addition of (i) 184 + 576 = 760 in BCD.
(ii) 842 + 537 = 1379 in BCD
show their steps needed to form their sum.
1.17 Add and subtract in binary:
(a) 1111 and 1001 (b) 1101001 and 110110 (c) 110010 and 11101
1.18 Subtract in binary. Place a 1 over each column from which it was necessary to borrow.
(a) 10100100 - 01110011 (b) 10010011 - 01011001 (c) 11110011 - 10011110
1.33 Add the following numbers in binary using 2’s complement to represent negative numbers.
Use a length of 8 bits (MSB is Sign-Bit) and indicate if an overflow occurs.
(a) (-10) + (-11) (b) (-10) + (-6) (c) (-8) + (-11) (d) 11 + 9 (e) (-11) + (-4)
Repeat using 1’s complement to represent negative numbers.
1.34 Because A - B = A + (-B), the subtraction of signed numbers can be accomplished by adding the complement.
Subtract each of the following pairs of 5-bit binary numbers by adding the complement of the subtrahend to the minuend.
Indicate when an overflow occurs. Assume that negative numbers are represented in 1’s complement.
Then repeat using 2’s complement.
(a) 01001 - 11010 (b) 11010 - 11001 (c) 10110 - 01101 (d) 11011 - 00111 (e) 11100 - 10101
(f) 11010 - 10100 (g) 01011 - 11000 (h) 10001 - 01010 (i) 10101 - 1101 (j) 11110 - 10111
1.37 (a) Assume the integers below are 1’s complement integers. Find the 1’s complement of each number, and give the decimal values of
the original number and of its complement.
(i) 0000000 (ii) 1111111 (iii) 00110011 (iv) 1000000
(b) Repeat, assuming the numbers are 2’s complement numbers and finding the 2’s complement of them.