# 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 ($X_{i}$), subtrahend ($Y_{i}$), and a borrow in from the previous (less significant) bit order position ($B_{i}$). The outputs are the difference bit ($D_{i}$) and borrow bit $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 $X_{i}-Y_{i}-B_{i}$ (which can take the values -2, -1, 0, or 1) as the sum $-2B_{i+1}+D_{i}$.

$D_{i} = X_{i} \oplus Y_{i} \oplus B_{i}$
$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.

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

## 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, X (minuend) and Y (subtrahend) and two outputs D (difference) and B (borrow).
An important point worth mentioning is that the half adder diagram aside implements (b-a) and not (a-b) as borrow is calculated from equation

$B = a \cdot \overline{b}$

This important difference should be noticed.

### Truth table

The truth table for the half subtractor is given below.[1]

X Y D B
0 0 0 0
0 1 1 1
1 0 1 0
1 1 0 0

From the above table one can draw the

 for "difference" and "borrow".


So, Logic equations are:

$D = y \oplus x$
$B = \overline{x} \cdot y$

## Full subtractor

Logic diagram of a Full Subtractor

The full-subtractor is a combinational circuit which is used to perform subtraction of three bits. It has three inputs, X (minuend) and Y(subtrahend) and Z (subtrahend) and two outputs D (difference) and B (borrow).
D=X-Y-Z (don't bother about sign)
B = 1 If X<(Y+Z)

### Truth table

The truth table for the full subtractor is given below.[1]

X Y Z D B
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

So, Logic equations are:

$D = X \oplus Y \oplus Z$

$B = Z \cdot (\overline{X \oplus Y}) + \overline{X} \cdot Y$