Half subtractor

A minus B, with a borrow bit for when you run out of room. A ready-made arithmetic circuit you can open in the TorchAnvil simulator.

Subtracting one bit from one bit

Subtraction looks a lot like addition at the bit level. 0 - 0 = 0, 1 - 0 = 1, 1 - 1 = 0 — easy. The awkward one is 0 - 1: you can't do it without reaching into the next column for help. That's a borrow, and a half subtractor catches it on a dedicated output.

How it works

Two gates, two outputs:

A B Diff Borrow
0 0 0 0
0 1 1 1
1 0 1 0
1 1 0 0

Why it matters

Chain a half subtractor with a full subtractor (accepts a borrow in as well as producing one out) and you have the subtraction equivalent of a ripple-carry adder. Most real CPUs don't bother, though — they reuse the adder by flipping B's bits and adding 1, the "two's complement" trick. Still, it's worth seeing subtraction built from first principles.

Try this