what can you build
out of switches?
image: ai-generated (gpt-image-2)
three things a computer does with bits
store them
move them
change them by rules

the toolbox: and, or, xor

two bits in, one bit out. a rule, nothing else.

and one that flips: not

with a not behind them: nand, nor, xnor

the small circle at the output means: and then flip it.

one gate is enough: nand

every chip is mostly nand. everything else is built from it.
no gate understands anything.
it just switches.

two nor gates, wired into each other

try it: the flip-flop

from one bit to memory

power off, and the loops collapse: RAM forgets.

excursion: what 32-bit and 64-bit mean

16 address lines choose one of 65,536 rows: 64 KB
1111 1111 1111 1111
the highest address a home computer from 1982 could name
32 address lines choose one of 4,294,967,296 rows: 4 GB
1111 1111 1111 1111 1111 1111 1111 1111
the wall of 32-bit windows: a fifth gigabyte of RAM has no address
64 address lines choose one of 18,446,744,073,709,551,616 rows: 16 EB
1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111
16 billion gigabytes: your laptop today, with room for a long time
every extra address line doubles the memory a computer can name.

1 + 1 in binary

0 + 0 = 00 0 + 1 = 01 1 + 0 = 01 1 + 1 = 10

the half adder: two gates

eight of them in a row: a byte adder

the carry runs from right to left, like in school.

the rest of arithmetic is built the same way

subtract=add the negativethe negative: flip every bit, then add one
multiply=add again and again× 2 is a shift to the left
compare=subtract, look at the sign
divide=subtract again and again
everything ends at the adder. the adder ends at four gates.

a photo is a grid of bytes

8 × 8 pixels from the parrot's beak
each pixel is one byte: 0 is black, 255 is white.
the numbers are the picture. the computer sees nothing else.

brighter: add 40 to every pixel

the yellow pixel:
the same addition as in the byte adder

…and the other 63, then all 16,384

before
after: every pixel + 40

more filters, same toolbox

darkernew = old − 40
negativenew = 255 − old
black & whitenew = old ≥ 128 ? 255 : 0
blend two photosnew = (a + b) ÷ 2
blurnine pixels at a time

try it: the pixel filter

xor over a byte: a check bit

flip one bit on the way, and the check bit no longer matches.

xor with a key: encryption

four gates, a few billion times a second.
that is all.
image: ai-generated (gpt-image-2)