Kōkiri Learn

Background reading · Technology

Zeros and ones: how computers store everything

How binary works, why computers use it, and how your score, your sprites and your sounds all become zeros and ones.

Inside every computer are billions of tiny switches. Each switch can only be on or off. We write on as 1 and off as 0. Every photo, song, message and game on your device is stored as a long pattern of these zeros and ones. This is called binary.

Counting with only two digits

We usually count in tens: ones, tens, hundreds. Binary counts in twos. Each place is worth double the place to its right: 1, 2, 4, 8, 16, 32 and so on. To write 13 in binary, find which places add up to 13: 8 + 4 + 1. So 13 is 1101 (one 8, one 4, no 2, one 1).

Bits and bytes

  • Bit: a single 0 or 1. The name comes from 'binary digit'. - Byte: a group of eight bits. One byte can store any number from 0 to 255. - Kilobyte, megabyte, gigabyte: thousands, millions and billions of bytes. A song might be a few megabytes; a big game can be many gigabytes.
  • Letters and pictures

    Computers store letters by giving each one a number, then storing the number in binary. Pictures are made of tiny squares called pixels. Each pixel's colour is stored as numbers for how much red, green and blue it has. Your Scratch sprite is a grid of pixels, and every one of them is stored as binary.

    Why only two?

    It is much easier to build a switch that is reliably on or off than one with ten different levels. Two states are fast, cheap and hard to confuse, even with a little electrical noise. That is why binary has been used in computers for more than 80 years.

    Binary in your game

    When your Scratch score reaches 7, the computer stores it as 111. When it reaches 8, it becomes 1000. Try the binary cards and see if you can read your final score in binary.

    Sources and further reading

    Written for Kōkiri Learn students in our own words. Check facts against the sources.

    Used in: Code a Game: Algorithms and Debugging