14Technology

How computers count

A computer has only switches that are on or off. Eight of them, fixed at the bottom of the screen, make one byte. Flip them and read the same pattern as a number, a letter, a counter that wraps round, and a colour.

Power on

Eight switches

Inside a computer everything is stored as switches that are either on or off. One switch is called a bit. Eight switches together are called a byte. That is all a computer has: a very large number of switches. Numbers, letters, pictures and sound are all patterns of switches.

The eight switches are fixed at the bottom of the screen. Flip them and read them in four ways: as a number, as a letter, as a counter and as a colour. Without a script, each panel shows one example.

Reading one

As a number

Each switch is worth double the one to its right: 1, 2, 4, 8, 16, 32, 64 and 128. To read the number, add up the value of every switch that is on. This way of counting with only two digits is called binary.

Eight switches can make 256 different patterns, which are the numbers from 0 to 255. Flip the switches, or type a number, and watch the sum.

64 + 1 = 65

The switches 64 and 1 are on. 64 + 1 = 65.

Reading two

As a letter

A computer has no letters, only numbers. So people agreed on a table that gives each letter a number. The table most used for English is called ASCII. In it a capital A is 65, B is 66, and so on up to Z, which is 90.

The same eight switches that made a number now make a letter. Set 65 and you get A. Flip one switch and you get a different letter. The table only has 128 places, so the top switch is always off.

Capital A

65 = 01000001

The byte 65 is a capital A in the ASCII table.

Reading three

As a counter

Add 1 to the switches and the pattern changes like the wheels of a car’s trip counter. When a switch is already on, adding turns it off and carries the 1 to the next switch on the left. Sometimes the carry runs all the way along.

Eight switches stop at 255. Add 1 again and every switch turns off: the byte wraps round to 0, and the last carry is lost. Doubling a number just shifts every switch one place to the left.

Press Add 1. When a switch is already on, it turns off and carries 1 to the next switch on the left.

Reading four

As a colour

A colour on a screen is a mix of red, green and blue light. Each of the three gets one byte, so each can be anything from 0 (none) to 255 (all). Three bytes make 24 switches, and 256 times 256 times 256 is 16,777,216 colours.

Your eight switches set the red. Use the two sliders for the green and the blue. The code under the colour is the same three bytes written in a short form that web pages use.

#4180C8

Red 65, green 128, blue 200. Three bytes make 24 switches, and 16,777,216 colours.

Your byte

65 01000001

Key takeaways

  1. A computer stores everything as switches that are on or off. One switch is a bit and eight switches are a byte.
  2. In binary each switch is worth double the one to its right (1, 2, 4, 8, 16, 32, 64, 128). Eight switches make 256 patterns, the numbers from 0 to 255.
  3. A letter is a number from an agreed table. In ASCII a capital A is 65 and a small a is 97, which is one switch apart.
  4. Adding 1 turns switches over and carries to the left. A byte wraps from 255 round to 0.
  5. A colour on a screen is three bytes, one each for red, green and blue: 16,777,216 colours.

Sources

Most of these sites could not be opened while this page was written, so the facts were checked through search results that quote them. The place values 128 to 1, the 256 patterns of a byte, A as 65 and a as 97 (one switch apart), the 16,777,216 colours of 24-bit colour, and the dates for Leibniz (1703) and for the word bit (a 1947 memo by Tukey, printed by Shannon in 1948) each appeared in at least two places. The sources disagree about exactly when Tukey first used the word, so only Shannon’s 1948 print is given. The panels are simple models made for this page.