Computer · Demo 6 of 19

How do computers count with only 0 and 1?

Inside every computer, numbers are stored as patterns of on and off. Drop marbles into a wooden machine and watch it count, carry and add, just like a processor does.

01248163264128
Marble
Chute1
Start again

Controls

Marbles
The marble rolling through the machineRockers: each shows 0 or 1 for its place valueEach rocker is one binary digit (a bit), worth the number on the plate under it. A marble that lands on a 0 flips it to 1 and drops into the tray. A marble that lands on a 1 flips it to 0 and rolls on to the next rocker: a carry. With a mouse you can also click a chute to drop a marble into it. The counter on the base shows the same number in ordinary digits.

Watch it work

A short film of this machine in action. Watch it, then try the challenges yourself.

What you're seeing

The machine has eight rockers in a row. Each one shows 0 or 1, and each is worth twice as much as the one to its right: 1, 2, 4, 8, 16, 32, 64 and 128. Add up the place values of the rockers showing 1 and you get the number on the counter.

Drop a marble into the 1s chute and it adds 1. When a rocker already shows 1, the marble flips it back to 0 and rolls on to the next rocker. That hand-off is called a carry, just like carrying a 1 when you add 9 + 1 = 10.

Try this

0 of 4 solved
  1. Drop marbles into the 1s chute one at a time and count to 16. What happens to the rockers at 16?Start from 0 (press Reset).
  2. Show a number between 10 and 18, like your age, using one marble for each 1 in its binary pattern.Pick chutes, not the 1s chute over and over.
  3. Make 5, then add 3, using 4 marbles or fewer. Watch the carries.5 = 4 + 1, and 3 = 2 + 1.
  4. What's the biggest number the eight rockers can show? Make it.Every rocker shows 1.

Why it works

A rocker can only be in two positions, so it can only store 0 or 1. With one rocker you can count to 1; each extra rocker doubles how far you can count. Eight rockers make 2 × 2 × 2 × 2 × 2 × 2 × 2 × 2 = 256 different patterns, the numbers 0 to 255.

Adding works by carrying. A rocker showing 1 that gets one more can't show 2, so it goes back to 0 and passes 1 to the next place, which is worth double. A computer's adder circuit does exactly this with electric switches instead of rockers, billions of times a second.

Go deeper AGES 14–16

In binary each place is worth twice the place to its right. Read a pattern by adding the place values that show 1:

1101 = 8 + 4 + 0 + 1 = 13

On your machine right now:

0000 0000
= 0 = 0
marbles used since reset: 0

Eight bits make one byte, which can hold 2⁸ = 256 values. Drop one more marble when every rocker shows 1 and they all flip to 0 while the last carry falls off the end into the cup: this is called overflow, and real programs have to watch out for it.