Chapter 4

Why Just 0 and 1?

A switch only ever has two states. So how does a pile of switches represent a number like 37, or your name, or a photo? It starts with a trick you already use every day without thinking about it: place value.

The trick you already know

Take the number 247. You don't think of it as one blob — you read it as three digits, each in its own column, each column worth ten times more than the one to its right:

hundreds (100)tens (10)ones (1)
247

2×100 + 4×10 + 7×1 = 247. That's the only trick to "regular" (decimal) numbers — columns worth powers of ten.

Binary numbers use the exact same trick, except each column is only allowed to hold a 0 or a 1 (because that's all a switch can store), and each column is worth twice the one to its right instead of ten times. Powers of two instead of powers of ten:

8421
0101

0×8 + 1×4 + 0×2 + 1×1 = 5. So the binary pattern 0101 is just the number 5, spelled out in switches.

Try it yourself

Below are 8 switches, each one a place value column just like above — worth 128, 64, 32, all the way down to 1. Click them on and off and watch the decimal number update live. See if you can make your age, or the current year.

Interactive
0
decimal value
00000000

That's genuinely the whole idea. A "byte" (8 switches like the ones above) can represent any number from 0 to 255 — 256 different patterns of on/off. Stack more switches together and you can represent bigger numbers, letters (each letter is just assigned a number), colors in a photo, anything. It's always the same underlying trick: patterns of 0s and 1s, interpreted as place value.

Coming up: now that a number can live inside a row of switches, how do we get a computer to actually add two numbers using nothing but the gates from Chapter 3?