TwiddleLab / Code / How Computers Store Everything
Bytes and Overflow
What you will learn
- A byte is 8 bits. It holds 2⁸ = 256 values: 0 to 255.
- n bits hold 2ⁿ values. Each extra bit doubles them.
- Binary addition: 1 + 1 = 10, so write 0 and carry 1.
- Overflow: when the answer needs more bits than the box has, the top carry is lost and the number wraps round to 0.
How the lesson goes
Pac-Man breaks on level 256. Why exactly 256?
The game keeps the level in 8 switches. Bet: what is the biggest number 8 switches can show?
The level counter is at 250. Keep adding 1.
Press +1 or Run, and watch what happens after every lamp is lit.
An online game has 1000 players. Each needs its own number.
How few switches can do it? Drag the slider until the bar reaches the line.
Bytes and overflow.
A byte is 8 bits. It holds 2⁸ = 256 different values, from 0 to 255. File sizes are counted in bytes.
n bits hold 2ⁿ values. One more bit doubles them: 8 bits 256, 10 bits 1024, 16 bits 65 536.
Overflow happens when an answer needs more bits than the box has. The top carry is lost and the number wraps round, like an odometer going from 999999 to 000000.
Add in binary: 0101 + 0011.
Fill the answer from the right, one column at a time.
Set your own high score in one byte.
Any number from 100 to 255. You'll see it again in the next game.
Odometer bets: predict the byte after the addition.
Set the bottom switches, then press Add it. Build a streak.
To fit an AI model on a phone, each of its numbers is squeezed into 8 bits. How many different values can each one take?
This trick is called quantization. It makes models about 4 times smaller.
This machine added 200 + 100 and got 44. Fix it.
Find what went missing, then give it a place.
Speed round: which numbers fit in one byte?
Drag each number into its jar.
Previous lesson: Switches Count · Next lesson: Letters Are Numbers · Part of the course: How Computers Store Everything
Lessons are interactive and need JavaScript. Turn it on to play them.