Counting with Light Bulbs

Counting with Light Bulbs: How Computers Work lesson banner with Beep and Pixel

Track: How Computers Work  ·  Lesson 2 of 10  ·  Ages: 8+  ·  Time: 35 minutes

Computers do not know what 7 or 42 means. Deep down, a computer only knows two things: on and off. So how does it do sums, show videos and play music? It counts using light bulbs! Well, imaginary ones.

Beep says My heart light is either glowing or dark. Glowing is 1. Dark is 0. Line up enough lights in a row and we can count as high as you like. Beep boop!

What you need

  • A pencil and paper.
  • Four small pieces of paper or card, for the activity.
  • About 35 minutes.

Two digits only

We count with ten digits, 0 to 9. A computer has switches that are either on or off, so it uses just two digits: 0 (off) and 1 (on). Counting with only 0 and 1 is called binary. One binary digit is called a bit.

Each bulb is worth a different number. Starting from the right, the values double every time: 1, 2, 4, 8, and then 16, 32, 64, 128 if you keep going. A bulb that is on adds its value. A bulb that is off adds nothing.

4 light bulbs showing 0101 in binary, which is 5

This row has four bulbs worth 8, 4, 2 and 1. The bulbs for 4 and 1 are on, so the number is 4 + 1 = 5.

4 light bulbs showing 1010 in binary, which is 10

Here the 8 and the 2 are on. That makes 8 + 2 = 10.

Pixel says Spot the pattern. Every bulb is worth double the one to its right. That is why binary is so tidy. Meow!

Counting from 0 to 7

Here is how the first few numbers look with four bulbs:

NumberBulbs (8 4 2 1)
00000
10001
20010
30011
40100
50101
60110
70111

Look at the right-hand column of bulbs. It goes off, on, off, on, off, on all the way down. When the 1 bulb has no more room to grow, the next bulb to the left switches on, just like a car’s odometer rolling over from 9 to 10.

With four bulbs you can make 16 different patterns, from 0 to 15. With eight bulbs you can make 256 patterns, from 0 to 255. Every extra bulb doubles the number of patterns.

Make your own bulbs

  1. Take four pieces of paper. Write 8 on the first, 4 on the second, 2 on the third and 1 on the fourth.
  2. Line them up in that order, 8 on the left.
  3. Turn a piece face up to mean the bulb is on, and face down to mean off.
  4. Ask a friend or grown-up to pick a number from 1 to 15 and keep it secret. Tell them to say it out loud when you are ready.
  5. Work out which pieces need to be face up. Start with the biggest number that fits, then keep going to the smaller ones.

For example, to make 11, start with 8. That leaves 3, so you need 2 and 1 as well. 8 + 2 + 1 = 11, so the pattern is 1011.

Let Python count in binary

Python can change a number into its bulb pattern. The code format(n, "08b") means “show the number n in binary, using 8 bulbs and filling empty spots with zeros”.

for n in [0, 1, 2, 5, 10, 37, 255]:
    print(n, "is", format(n, "08b"))
print(bin(5))
0 is 00000000
1 is 00000001
2 is 00000010
5 is 00000101
10 is 00001010
37 is 00100101
255 is 11111111
0b101

The last line uses the built-in bin function. The 0b at the start just tells you “a binary number follows”. The digits after it, 101, are the same as 5.

Did you know? The biggest number you can make with eight bulbs is 255, when every bulb is on. That is 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1. Later you will see why 255 turns up everywhere in computing.

Challenges

Try it What number is shown by these eight bulbs?

8 light bulbs showing 00100101 in binary, which is 37
Show the answer

The bulbs that are on are worth 32, 4 and 1. Add them up: 32 + 4 + 1 = 37. You can check it in the Python output above, where 37 is shown as 00100101.

Try it Write the numbers 9 and 12 as four bulbs. Then use Python to check your answers.

Show the answer

9 = 8 + 1, so the bulbs are 1001. 12 = 8 + 4, so the bulbs are 1100. To check, run print(format(9, "04b")) and print(format(12, "04b")). The 04b means “use 4 bulbs”.

Grown-ups Place value is the key idea here. A child who understands why 345 means 3 hundreds, 4 tens and 5 ones is ready for binary, which just changes the place values from 100, 10, 1 to 4, 2, 1. The paper-card game works well with a few friends or a whole class, taking turns to be the “computer”.

What you learned

  • Computers use only two digits, 0 and 1, because their tiny switches are either off or on.
  • This way of counting is called binary, and one digit is a bit.
  • Each bulb is worth double the one on its right: 1, 2, 4, 8, 16, 32, 64, 128.
  • Four bulbs make 16 patterns and eight bulbs make 256 patterns.
  • Python’s format(n, "08b") shows a number as eight bits.