Two-bit binary adder, built from NAND gates
Two bits plus two bits, with a carry in and a carry out. Flip the switches on the left rail and the answer appears on the right.
Underneath there are exactly two parts: an ADDER for the low bit and another
for the high one, with the low adder’s carry-out wired into the high adder’s
carry-in. That single wire is the whole idea of ripple-carry arithmetic, and
it is also its weakness — the high bit cannot settle until the low bit has,
so a wide adder built this way gets slower in proportion to its width.
What one bit of addition costs
Click either ADDER and it opens as a workspace of its own. Inside are two
XORs, two ANDs and an OR; open the XOR and you find four NANDs. Follow
it all the way down and the whole board is 30 NAND gates — about 120
transistors in CMOS to add two two-bit numbers.
The sum bit is A XOR B XOR CIN. The carry-out is high when at least two of
the three inputs are high, which the adder computes as
(A AND B) OR ((A XOR B) AND CIN).
Things worth trying
- Set both inputs to
11with the carry in high: the result is111, three bits from two two-bit numbers, which is whyCOUTexists at all. - Chain further: the
ADD-4module in the library is the same trick with four stages, andADDSUB-4adds aSUBline that flips every B bit and rides into the carry-in — turningA + BintoA - Bwith no extra adder.
Built out of NAND gates and nothing else. The sandbox, the JSON module format and the rest of the library are described in Digital logic — from NAND to a computer.