cadence_learn
think_like_a_programmer / level 08 of 12 ▶ 14 min

it is all numbers.

Text, pictures, sound and the program itself — all one kind of thing, written with two digits. Flip eight switches, watch letters turn into numbers, and meet the reason 0.1 plus 0.2 is not 0.3.

after this level you'll be able to
  • Read and build a binary number using place values
  • Explain why limits like 255 and 65,535 keep appearing
  • Say why you must never test two decimals for exact equality
the whole idea

there is only one kind of thing in there

the one sentence

A computer stores exactly one kind of thing: numbers. Text is numbers, colours are numbers, sound is numbers, your photos are numbers, and the program itself is numbers. The only question is what the numbers are agreed to mean.

one pattern, several meanings
EIGHT SWITCHES — EACH WORTH DOUBLE THE ONE ON ITS RIGHT 0 128 1 64 0 32 0 16 0 8 0 4 0 2 1 1 64 + 1 = 65 the number 65 …which everyone agreed also means the letter A The same eight switches are a number, a letter, a shade of grey, or a fragment of sound. Nothing in the switches says which. The meaning lives entirely in what the program was told to expect. All eight on = 255. That is not a design decision — it is simply what running out of switches looks like.
One pattern, several meanings. This is why C++ makes you declare a type: the bits cannot tell the machine whether they are a number or a letter, so you have to.

And underneath even that, the numbers are written with only two digits, 0 and 1, because a wire is either carrying current or it is not. Two states is the one thing electronics can be reliably sure about. Everything is built on that.

A single 0-or-1 is a bit. Eight of them together is a byte. That is not trivia — it is the reason for a pile of things that will otherwise look arbitrary in C++, including why a whole number has a maximum size and why it goes strange when you pass it.

try it yourself

build a number out of switches

Eight switches. Each one is worth double the one to its right. Turn some on and read the total — that is genuinely all binary is.

▤ lab 08a · eight switches

Click the switches. Try to make 1, then 7, then 255.

0
binary 00000000
All off. Every switch is worth nothing when it is off.
Turn on the far-right switch. That is 1. Now the one next to it. That is 2, then 3 with both on.
why 255 keeps showing up

Eight switches, all on, is 255 — the biggest number a single byte can hold. That is why so many limits in computing are 255, or 65,535, or 4,294,967,295. They are not chosen. They are just what you get when you run out of switches. In C++ this becomes real: a value that goes past its maximum does not error, it silently wraps around to the bottom.

◈ ask an ai about this

“Why do computers use only 0 and 1, and what is the difference between a bit and a byte?”

chatgpt ↗ claude ↗

so what about letters

text is numbers with an agreement

If the machine only holds numbers, a letter has to be a number too. So everyone agreed on a table: 65 means A, 66 means B, 97 means a. That is the whole trick — there is nothing letter-like about the number 65.

▤ lab 08b · type something

Every character you type is stored as the number underneath it.

Change the text and watch the numbers change with it.

Try typing a capital A and then a lowercase a. They differ by exactly 32 — and that is not a coincidence, it is one bit. In C++ you will meet char, which is a small number wearing a letter's clothes, and you will be able to add to it.

◈ ask an ai about this

“How does a computer store letters if it can only store numbers? What are ASCII and Unicode?”

chatgpt ↗ claude ↗

the one that catches everybody

the computer cannot count in tenths

Here is a genuinely famous one, and it is not a bug. Ask any computer to add nought point one and nought point two:

▤ lab 08c · run it right now

This is running in your browser, live, on this page.

Press the button. The answer is not what you were taught in school.

The reason is the switches. In our ten-fingered notation, a third has no exact form — 0.333… goes on forever and you have to stop somewhere. In a two-state machine, a tenth is that same kind of number. It cannot be written exactly with any number of switches, so it is stored very slightly wrong, and the error shows up when you add.

the rule this gives you, and you will need it

Never check whether two decimal numbers are exactly equal. Ask whether they are close enough. This will cost somebody in your class an entire evening this semester, because their answer was right and the comparison said no. And never store money as a decimal — store whole pennies.

do this together

count on your fingers, in binary

☶ two people · 8 minutes · just hands

One hand is five switches. Down is 0, up is 1.

person a

Count out loud from 1 upward, raising fingers as binary switches — thumb is 1, index is 2, middle is 4, ring is 8, little is 16.

person b

Call out the total each time and catch the mistakes. Then say a number under 31 and make A show it.

One hand reaches 31, not 5. Two hands reach 1,023. That jump — five switches giving thirty-one, ten giving a thousand — is the same doubling that made halving so powerful in level six. Same idea, met from the other end.

what to keep

three things worth remembering

01

It is all numbers

Text, pictures, sound, and your program itself. The meaning comes from what everyone agreed.

02

Limits come from switch count

255 and 65,535 are not decisions. They are what running out of bits looks like.

03

Decimals are approximate

Compare them for closeness, never for exact equality. Keep money in whole pennies.

check yourself

3 questions before you move on

Not recall — these are the shapes an exam actually uses. Every answer below was produced by compiling and running the code, so if you disagree with one, the compiler is the one to believe.

▢ check yourself3 questions

Have a real go before revealing. Being wrong here is worth more than being right in three weeks.

01

Eight switches, worth 128, 64, 32, 16, 8, 4, 2, 1 from left to right. The pattern is 01000001. What number is it?

128 64 32 16 8 4 2 1 0 1 0 0 0 0 0 1
02

All eight switches on. What is the biggest number you can make?

03

Is 0.1 + 0.2 exactly equal to 0.3 in a computer?

answered: 0 of 3right first time: 0
Stuck? Peter reads these personally and replies to your email.
Ask Peter →