Skip to content
digiwleeaTools
LearnGlossaryAboutCheat sheetHow a CPU worksBuild a CPUToolsOpen the lab →

4-bit decrementer: subtract 1 with half subtractors, live

A 4-bit decrementer subtracts 1 from a 4-bit number: D = A - 1, with a borrow out when A is 0000, which wraps to 1111. It needs no B input, so instead of full subtractors it is a chain of four half subtractors, the first taking the constant 1 from A0 and each passing its borrow to the next.

Counting down is the mirror image of counting up. A down counter computes A - 1 as its next state, a loop counter in a program is decremented until it reaches zero, and a stack pointer is decremented on every push in many CPUs. Because the second operand is the constant 0001, each column subtracts only two bits, the borrow from below from Ai, which is exactly a half subtractor: Di = Ai XOR Bi and the borrow out is NOT Ai AND Bi. The pattern is easy to read off: the decrementer flips every bit up to and including the lowest 1, so 1000 becomes 0111. The borrow keeps rippling through the 0 bits and stops at the first 1. If every bit is 0 there is no 1 to stop it, so 0000 - 1 gives 1111 with a borrow out, the same answer as -1 in two's complement. The half subtractors here are the verified half subtractor, saved as a part. All 16 inputs are checked before the page is built; the live circuit starts at 1000, so the borrow ripples through all four stages and D shows 0111.

Live circuit: click the inputs to toggle them and watch the outputs update. It runs the real simulator, right here on the page.

Open this circuit in the lab →

Embed or cite this circuit

Free to embed on a course page, blog or worksheet: paste this code. The circuit stays live, and the small digiwleea badge links back here.

To cite it: digiwleea, “4-bit decrementer”, https://digiwleea.wleeaf.dev/tools/build/decrementer-4bit/

What you need

Step by step

  1. Place inputs A3 to A0 and probes D3 to D0 and Bout.
  2. Feed A0 and a constant 1 into the first half subtractor; its difference is D0 (NOT A0).
  3. Feed each next bit Ai and the borrow from the half subtractor below into the next half subtractor; its difference is Di.
  4. The last half subtractor's borrow is Bout, which is 1 only for 0000 - 1.
  5. Count A down from 1111 to 0000: D is always one less, wrapping to 1111 with Bout = 1.

4-bit decrementer truth table

A3 A2 A1 A0D3 D2 D1 D0BoutDecimal
0000111110 - 1 wraps to 15 (borrow)
0001000001 - 1 = 0
0010000102 - 1 = 1
0011001003 - 1 = 2
0100001104 - 1 = 3
0101010005 - 1 = 4
0110010106 - 1 = 5
0111011007 - 1 = 6
1000011108 - 1 = 7
1001100009 - 1 = 8
10101001010 - 1 = 9
10111010011 - 1 = 10
11001011012 - 1 = 11
11011100013 - 1 = 12
11101101014 - 1 = 13
11111110015 - 1 = 14

All 16 rows, with all five outputs each, are checked on the live circuit before the page is built. The 4-bit incrementer is the same idea with half adders and a carry chain: A + 1 flips every bit up to and including the lowest 0.

You can also read the full theory in the lesson on the half subtractor. 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 decrementer in the lab →

Frequently asked

What is a 4-bit decrementer?

A combinational circuit that outputs its 4-bit input minus 1, with a borrow out when the input is 0000 (which wraps to 1111). Down counters and loop counters use it.

How do you design a decrementer circuit?

Chain half subtractors, one per bit. The first subtracts a constant 1 from A0, and each later stage subtracts the borrow from the stage below: Di = Ai XOR Bi and the next borrow is NOT Ai AND Bi.

Can you build a decrementer from adders?

Yes. Subtracting 1 is the same as adding 1111, the two's complement of 0001, and ignoring the carry out. A 4-bit adder with B = 1111 works, but it needs four full adders, while the half subtractor chain gets by with fewer gates.

How many gates does a 4-bit decrementer need?

Four half subtractors, each one XOR, one NOT and one AND, so twelve gates. The first stage subtracts a constant 1, so it reduces to D0 = NOT A0 and borrow = NOT A0, which a simplified design can use to save gates.

What is the difference between an incrementer and a decrementer?

An incrementer adds 1 with a carry chain and flips bits up to the lowest 0; a decrementer subtracts 1 with a borrow chain and flips bits up to the lowest 1. 1111 + 1 and 0000 - 1 are the two cases that wrap around.