4-bit subtractor: A minus B with four full adders, live
A 4-bit subtractor computes D = A - B by adding the two's complement of B: four full adders in a ripple chain, an inverter on each B bit, and the first carry-in tied to 1, so the adders compute A + NOT B + 1. The borrow Bout = NOT Cout is 1 when B is larger than A.
Subtracting with an adder needs one identity: in 4 bits, minus B is NOT B + 1 (the two's complement). The inverters make NOT B, and the 1 enters as the carry into the lowest full adder, so no extra adder is needed for it. The carry out of the top adder then means "no borrow": it is 1 when A is at least B and 0 when the subtraction wrapped around, so the borrow output is its inverse. Read D as an unsigned difference when Bout = 0; when Bout = 1, D is the 4-bit two's-complement result, for example 3 - 5 gives 1110, which is -2. This is a subtract-only circuit; the 4-bit adder/subtractor swaps the fixed inverters for XOR gates and the fixed 1 for a SUB input, so one circuit does both. The bit-by-bit alternative is a chain of full subtractors, which compute the same D and borrow with borrow logic instead of an adder.
Open this circuit in the lab →
What you need
- 4× full adder: the ripple chain, bit 0 to bit 3
- 4× NOT: NOT B, one per bit
- 1× constant 1: carry into bit 0: the + 1 of the two's complement
- 1× NOT: Bout = NOT Cout
Step by step
- Place inputs
A3toA0andB3toB0, and probesD3toD0andBout. - Chain four full adders: each carry out feeds the next carry in.
- Feed A straight into the adders and B through a NOT gate per bit.
- Tie the carry in of bit 0 to 1, and invert the last carry out to get
Bout. - Try 9 - 4: D = 0101 (5) and Bout = 0. Then 4 - 9: D = 1011 (-5 in two's complement) and Bout = 1.
4-bit subtractor: example rows
| A | B | A + NOT B + 1 | D3..D0 | Bout |
|---|---|---|---|---|
| 9 (1001) | 4 (0100) | 1001 + 1011 + 1 = 1 0101 | 0101 (5) | 0 |
| 7 (0111) | 7 (0111) | 0111 + 1000 + 1 = 1 0000 | 0000 (0) | 0 |
| 15 (1111) | 1 (0001) | 1111 + 1110 + 1 = 1 1110 | 1110 (14) | 0 |
| 3 (0011) | 5 (0101) | 0011 + 1010 + 1 = 0 1110 | 1110 (-2) | 1 |
| 0 (0000) | 1 (0001) | 0000 + 1110 + 1 = 0 1111 | 1111 (-1) | 1 |
The leading digit of the sum is the carry out; Bout is its inverse. Before the page is built, all 256 pairs of A and B are checked on the live circuit against ordinary 4-bit subtraction.
You can also read the full theory in the lesson on negative numbers and subtraction. Prefer to build it yourself from scratch? Open the digiwleea lab and place the gates on the canvas, or start from the logic gate simulator.
More builds: Arithmetic
All 246 build guides, by topic
Each of these is one step from a transistor to a working CPU. Build every gate from CMOS transistors and work all the way up in the free digiwleea lab, with the free theory reference alongside.
Open the 4-bit subtractor in the lab →Frequently asked
How do you make a 4-bit subtractor?
Use a 4-bit ripple-carry adder, invert every bit of B, and set the first carry in to 1. The adder then computes A + NOT B + 1, which is A - B in two's complement.
What does the borrow output of a 4-bit subtractor mean?
Bout = 1 means B was larger than A, so the result went below zero and D holds the negative difference in two's complement. With this adder design, Bout is the inverse of the last carry out.
Why is the carry in set to 1 in a subtractor?
Because the two's complement of B is NOT B plus 1. Feeding the 1 in as the first carry adds it without a separate adder.
What is the difference between a subtractor and an adder-subtractor?
A subtractor always computes A - B. An adder-subtractor has a mode input that XORs B and sets the carry in, so the same circuit adds when the mode is 0 and subtracts when it is 1.