# Subtractor

(Redirected from Half subtractor)

In electronics, a subtractor 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 (${\displaystyle X_{i}}$), subtrahend (${\displaystyle Y_{i}}$), and a borrow in from the previous (less significant) bit order position (${\displaystyle B_{i}}$). The outputs are the difference bit (${\displaystyle D_{i}}$) and borrow bit ${\displaystyle B_{i+1}}$. The subtractor is best understood by considering that the subtrahend and both borrow bits have negative weights, whereas the X and D bits are positive. The operation performed by the subtractor is to rewrite ${\displaystyle X_{i}-Y_{i}-B_{i}}$ (which can take the values -2, -1, 0, or 1) as the sum ${\displaystyle -2B_{i+1}+D_{i}}$.

${\displaystyle D_{i}=X_{}\oplus Y_{i}\oplus B_{i}}$
${\displaystyle B_{i+1}=X_{i}<(Y_{i}+B_{i})}$

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.

${\displaystyle -B={\bar {B}}+1}$ (definition of two's complement notation)
{\displaystyle {\begin{alignedat}{2}A-B&=A+(-B)\\&=A+{\bar {B}}+1\\\end{alignedat}}}

## Half subtractor

Logic diagram for a half subtractor

The half subtractor is a combinational circuit which is used to perform subtraction of two bits. It has two inputs, the minuend ${\displaystyle X}$ and subtrahend ${\displaystyle Y}$ and two outputs the difference ${\displaystyle D}$ and borrow out ${\displaystyle B_{\text{out}}}$. The borrow out signal is set when the subtractor needs to borrow from the next digit in a multi-digit subtraction. That is, ${\displaystyle B_{\text{out}}=1}$ when ${\displaystyle X. Since ${\displaystyle X}$ and ${\displaystyle Y}$ are bits, ${\displaystyle B_{\text{out}}=1}$ if and only if ${\displaystyle X=0}$ and ${\displaystyle Y=1}$. An important point worth mentioning is that the half subtractor diagram aside implements ${\displaystyle X-Y}$ and not ${\displaystyle Y-X}$ since ${\displaystyle B_{\text{out}}}$ on the diagram is given by

${\displaystyle B_{\text{out}}={\overline {X}}\cdot Y}$.

This is an important distinction to make since subtraction itself is not commutative, but the difference bit ${\displaystyle D}$ is calculated using an XOR gate which is commutative.

Half adder using NAND gate only.

The truth table for the half subtractor is:

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 ${\displaystyle D}$ and ${\displaystyle B_{\text{out}}}$:

${\displaystyle D=X\oplus Y}$
${\displaystyle B_{\text{out}}={\overline {X}}\cdot 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 otherwise


where lines to the right are outputs and others (from the top, bottom or left) are inputs.

## Full Subtractor

The full subtractor is a combinational circuit which is used to perform subtraction of three input bits: the minuend ${\displaystyle X}$, subtrahend ${\displaystyle Y}$, and borrow in ${\displaystyle B_{\text{in}}}$. The full subtractor generates two output bits: the difference ${\displaystyle D}$ and borrow out ${\displaystyle B_{\text{out}}}$. ${\displaystyle B_{\text{in}}}$ is set when the previous digit borrowed from ${\displaystyle X}$. Thus, ${\displaystyle B_{\text{in}}}$ is also subtracted from ${\displaystyle X}$ as well as the subtrahend ${\displaystyle Y}$. Or in symbols: ${\displaystyle X-Y-B_{\text{in}}}$. Like the half subtractor, the full subtractor generates a borrow out when it needs to borrow from the next digit. Since we are subtracting ${\displaystyle X}$ by ${\displaystyle Y}$ and ${\displaystyle B_{\text{in}}}$, a borrow out needs to be generated when ${\displaystyle X. When a borrow out is generated, 2 is added in the current digit. (This is similar to the subtraction algorithm in decimal. Instead of adding 2, we add 10 when we borrow.) Therefore, ${\displaystyle D=X-Y-B_{\text{in}}+2B_{\text{out}}}$.

Full subtractor circuit

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 and Bout=X'Bin+X'Y+YBin

## References

Foundations Of Digital Electronics by Elijah Mwangi