In electronics, a subtractor – a digital circuit that performs subtraction of numbers – can be designed using the same approach as that of an adder. The binary subtraction process is summarized below. As with an adder, in the general case of calculations on multi-bit numbers, three bits are involved in performing the subtraction for each bit of the difference: the minuend (
Xi
Yi
Bi
Di
Bi+1
Xi-Yi-Bi
-2Bi+1+Di
Di=X ⊕ Yi ⊕ Bi
Bi+1=Xi<(Yi+Bi)
Subtractors are usually implemented within a binary adder for only a small cost when using the standard two's complement notation, by providing an addition/subtraction selector to the carry-in and to invert the second operand.
-B=\bar{B}+1
\begin{alignat}{2} A-B&=A+(-B)\\ &=A+\bar{B}+1\\ \end{alignat}
X
Y
D
Bout
Bout=1
X<Y
X
Y
Bout=1
X=0
Y=1
X-Y
Y-X
Bout
Bout=\overline{X} ⋅ Y
D
Inputs | Outputs | ||
---|---|---|---|
X | Y | D | Bout |
0 | 0 | 0 | 0 |
0 | 1 | 1 | 1 |
1 | 0 | 1 | 0 |
1 | 1 | 0 | 0 |
Using the table above and a Karnaugh map, we find the following logic equations for
D
Bout
D=X ⊕ Y
Bout=\overlineX ⋅ Y
Consequently, a simplified half-subtract circuit, advantageously avoiding crossed traces in particular as well as a negate gate is:
X ── XOR ─┬─────── |X-Y|, is 0 if X equals Y, 1 otherwise ┌──┘ └──┐ Y ─┴─────── AND ── borrow, is 1 if Y > X, 0 otherwisewhere lines to the right are outputs and others (from the top, bottom or left) are inputs.
The full subtractor is a combinational circuit which is used to perform subtraction of three input bits: the minuend
X
Y
Bin
D
Bout
Bin
X
Bin
X
Y
X-Y-Bin
Y
Bin
X
X<Y+Bin
D=X-Y-Bin+2Bout
The truth table for the full subtractor is:
Inputs | Outputs | ||||
---|---|---|---|---|---|
X | Y | Bin | D | Bout | |
0 | 0 | 0 | 0 | 0 | |
0 | 0 | 1 | 1 | 1 | |
0 | 1 | 0 | 1 | 1 | |
0 | 1 | 1 | 0 | 1 | |
1 | 0 | 0 | 1 | 0 | |
1 | 0 | 1 | 0 | 0 | |
1 | 1 | 0 | 0 | 0 | |
1 | 1 | 1 | 1 | 1 |
Therefore the equation is:
D=X ⊕ Y ⊕ Bin
Bout=\bar{X}Bin+\bar{X}Y+YBin