Adding Two Numbers Using Only NAND Gates

It's possible to build any kind of digital logic using a single type of logic gate: either NAND gates, or NOR gates. A NAND gate takes two input bits (A and B) and produces one output bit according to this simple rule: "0 if both inputs are 1, otherwise 1"

A B A NAND B
0 0 1
0 1 1
1 0 1
1 1 0

Any other logic function (AND, OR, NOT, XOR, etc.) can be constructed from combinations of NAND gates.

The following interactive component is an 8-bit ripple-carry adder built entirely from NAND gates. You can input two numbers (from 0-255), and watch the binary signals propagate through the circuit to produce the sum. (You can also click the individual input bits.)

You can view the source code on GitHub:

physics_sim/logic_gates/web_viz at main · ndbroadbent/physics_sim
Experimenting with physics simulations, solar efficiency, etc. - ndbroadbent/physics_sim