From truth tables and universal NAND gates up to the half and full adders that do arithmetic.
A logic gate is the smallest building block of a computer: a tiny circuit that takes one or two bits in and produces one bit out. Each gate is completely defined by its truth table — a list of the output for every possible input. Stack enough of them and you get an entire processor.
NOT a = a NAND a, a AND b = (a NAND b) NAND (a NAND b), and a OR b = (a NAND a) NAND (b NAND b).Add two single bits A and B and you get a sum and a possible carry. Two gates do it: Sum = A XOR B and Carry = A AND B. That is a half adder — "half" because it cannot accept a carry coming *in* from a previous column.
Half adder truth table:
A B | Sum Carry
0 0 | 0 0
0 1 | 1 0
1 0 | 1 0
1 1 | 0 1 <- 1 + 1 = binary 10
Sum = A XOR B
Carry = A AND BTo add a column inside a real multi-bit number you need three inputs: A, B, and the carry-in from the column to the right. A full adder does this with Sum = A XOR B XOR Cin and Carry = (A AND B) OR (Cin AND (A XOR B)) — effectively two half adders plus an OR. This one cell, repeated once per bit, is exactly what a ripple-carry adder chains together.