1.1.1 · D2How Computers Work

Visual walkthrough — Binary number system — conversions from - to decimal, counting in binary

1,889 words9 min readBack to topic

We build everything. If a symbol appears, it was defined the line before. Ready? One switch at a time.


Step 1 — A switch has exactly two states

WHAT. Picture a single light switch on a wall. It can only be down (OFF) or up (ON). Nothing in between counts.

WHY. A computer is built from millions of tiny switches (transistors). We choose a name for each state: OFF is called 0, ON is called 1. The word "bit" just means "one such switch" — a thing that holds a 0 or a 1. We use two states (and not ten) because a switch that only has to be clearly-down or clearly-up is cheap and rarely misread.

PICTURE. In the figure, the left switch is down (we write 0 under it) and the right switch is up (we write 1 under it). That label under each switch is its bit.

Figure — Binary number system — conversions from - to decimal, counting in binary

Step 2 — A row of switches, and "position"

WHAT. Line up several switches side by side. Reading right-to-left, we give each a position number starting at : the rightmost switch is position , the next is position , then , then , and so on.

WHY. We start counting positions at 0, not 1, because in a moment each position will get a value , and we want the rightmost switch to be worth . If we started at 1 the rightmost would wrongly be worth . Starting at 0 makes the maths line up.

Here each (read "dee-eye") is just the bit sitting at position — a stand-in that is either 0 or 1. The little number tells you which switch we mean.

PICTURE. The figure numbers the switches from the right. Notice the arrow: position numbers grow as we move left.

Figure — Binary number system — conversions from - to decimal, counting in binary

Step 3 — Each position is worth double the one to its right

WHAT. Give position the weight . Reading right-to-left the weights are — each one is double its right neighbour.

WHY doubling, and why powers of 2? Because there are only two digits. In decimal a new column appears once you'd need a digit bigger than 9 — so decimal columns are worth each. In binary a new column appears the moment you'd need a digit bigger than 1 — so each binary column is worth . That "times two per step to the left" is exactly what "powers of two" means:

The exponent (the small raised number) counts how many times we multiplied by 2. Position multiplied zero times gives .

PICTURE. Above each switch we chalk its weight. The blue arrow shows the "" jump from one column to the next as you step left.

Figure — Binary number system — conversions from - to decimal, counting in binary

Step 4 — A bit either "collects" its weight or it doesn't

WHAT. Multiply each bit by its weight: the column contributes . Because is only ever 0 or 1, this multiplication has just two outcomes.

WHY this is the key trick. Look at what does:

  • If the switch is off (): . It contributes nothing.
  • If the switch is on (): . It contributes its full weight.

So a bit acts like a gate on its weight: a 1 lets the weight through, a 0 blocks it. There is no in-between because there is no other digit. This is why binary is easy to add up — you never scale a weight by 3 or 7, only by 0 or 1.

PICTURE. Green switches (on) pass their weight down; grey switches (off) drop a . The values that survive are circled.

Figure — Binary number system — conversions from - to decimal, counting in binary

Step 5 — Sum the surviving weights (the formula appears)

WHAT. Add every column's contribution. Written all at once, that sum is the binary-to-decimal formula.

WHY a sum (the symbol). We are combining many separate contributions into one total, so the natural tool is addition. The symbol (a big Greek "S", for "Sum") is shorthand for "add up all of these":

Read it term by term:

  • — "add together everything that follows".
  • underneath — start the counter at the rightmost column.
  • on top — stop at the leftmost column (position ).
  • — the one contribution being added: bit times its weight.

Because each is 0 or 1, this long sum quietly becomes "add the weights where the bit is 1", exactly Step 4.

PICTURE. The figure lays out : weights on top, bits below, and only the on-columns feed the running total .

Figure — Binary number system — conversions from - to decimal, counting in binary

Step 6 — A bigger number, same picture ()

WHAT. Convert by the exact same method — just more columns.

WHY show a longer one. To prove the recipe doesn't change with size, and to make you see the zeros doing their job (contributing nothing while still holding a position).

Weights (right-to-left): . Bits: .

On-columns are positions :

PICTURE. Six switches; the three zero-switches sit dark but still occupy their slots, so the weights above them () are simply skipped, not deleted.

Figure — Binary number system — conversions from - to decimal, counting in binary

Step 7 — The degenerate cases: all-zeros and all-ones

WHAT. Two edge cases you must never trip over.

All switches off. Every term is , so the total is . Binary zero is just "all off". No special rule needed; the formula already handles it.

All switches on ones in a row. Now every weight survives, so we add the whole staircase:

WHY the , visually. Stack the weights and add one more : it fills every gap and rolls all the way up to the next power of two, landing one short — . Example: . This is why bits reach a maximum of , not : you start counting at , so the last of the values is one below .

PICTURE. The tower of weights plus a phantom (pink) tips the whole stack up to , then we step back down one to .

Figure — Binary number system — conversions from - to decimal, counting in binary
Recall Why does 8 bits max out at 255?

All eight on: . ::: values ( through ), largest is .


The one-picture summary

WHAT. One figure that fuses the whole walkthrough: switches on top, weights hovering over each, on-switches lighting a path down into a single sum, out pops the decimal number.

Figure — Binary number system — conversions from - to decimal, counting in binary

The pipeline you now own:

number from right at 0

weight is two to the i

on keeps weight off drops zero

add them up

Row of switches

Positions 0 1 2 3

Weights 1 2 4 8

Surviving weights

Decimal number

Recall Feynman retelling — say it to a friend

Lay out some light switches. Number them from the right, starting at zero. Give the rightmost one the value 1, and each switch to its left is worth double: 1, 2, 4, 8, 16… Now walk the row: if a switch is ON, keep its value; if it's OFF, throw a zero away. Add up everything you kept — that total is the number the switches spell. All off means zero. All on means you kept every value, which stacks up to one below the next doubling. That's the whole game: add the weights of the switches that are on.


Connections

  • Place-value and number bases — this whole page is the case of .
  • Bits and Bytes — 8 switches in a row = a byte, values (Step 7).
  • Logic gates and switcheswhy each switch has only two states.
  • Hexadecimal and Octal — grouping these switches into blocks for shorter writing.
  • Binary addition and overflow — what happens when the "on" columns start to carry.
  • Two's complement — reusing the leftmost switch to mean "negative".