Explain the working of a two’s complement adder/subtractor.
Often in binary arithmetic circuits we need to have a device that completes an entire binary string when told to do so by some control signal. Figure 10.28 shows a controlled inverter. When INVERT is LOW, it transmits the 8-bit input to the output; when INVERT is HIGH, it transmits the 1’s complement. For instance, if the input number is
D_{7} \ldots D_{0}=0110 1110
a L O W INVERT produces
X_{7} \ldots X_{0}=01101110
But a HIGH INVERT results in
X_{7} \ldots X_{0}=10010001
The controlled inverter is important because it is very helpful in subtraction. During a subtraction, we first need to take the 2’s complement of the subtrahend. Then we can add the complemented subtrahend to obtain the answer. With a controlled inverter, we can produce the 1’s complement. There is an easy way to get the 2’s complement.
Figure 10.28 can be used to provide the complementing function. If the INVERT (\mathrm{C}) is HIGH, each of the data bits is complemented at the output. If the INVERT (\mathrm{C}) is LOW, the data bits pass through to the output uncomplemented. Two 7486 quad Ex-OR ICs could be used to implement this design.
Positive two’s-complement numbers are exactly the same as regular true binary numbers and can be added using regular binary addition. Also, subtraction in two’scomplement arithmetic is performed by converting the number to be subtracted to a negative number in the two’s-complement form and then using regular binary addition. Therefore, once our numbers are in two’scomplement form, we can use a binary adder to get the answer whether we are adding or subtracting.
For example, to perform the subtraction 18-9, we would first convert 9 to a negative two’s-complement number by complementing each bit and then adding 1 . We would then add 18+(-9).
Two’s complement of 18=00010010
+ Two’s complement of -9=11110111
\text { Sum }=\overline{00001001}=9_{10}
All we need for a combination adder/subtractor circuit is an input switch or signal to signify addition or subtraction so that we will know whether to form a positive or a negative two’s-complement of the second number. Then we will just use a binary adder to get the final result.
To form negative two’s complement, we can use the controlled inverter circuit of Fig. 10.28 and add 1 to its output.