← Teacher guides

Teacher guide: Data representation

Everything a computer stores is numbers: text as character codes, pictures as pixels, sound as samples. Then how those numbers are stored with only 0s and 1s: binary place value, how many numbers a few bits can hold, logic gates, and the chain from any data down to bytes.

Open the student course

Each lesson works two ways. Students can work through the online tutorial at their own pace (it checks their answers and saves their progress in their browser), or you can teach it to the whole class from the slides, then send students into the tutorial for the Modify and Make steps.

Every lesson guide has plain-language notes, the answers to every check, a solution for every task, and slides and a worksheet for Waypoints Prepare. These guide pages are not linked from student pages, but they are not secret either: keep printed Teacher editions for answers you do not want students to find.

Whole-course cheat sheet: Open to print (every command, grouped by unit: a handout for the final challenge)

Data as numbers

Text, pictures and sound are all stored as numbers, and the encoding decides what they mean: character codes, RGB pixels, shapes and sound samples.

Cheat sheet: Open to print (A4, with board pictures) · Markdown

Binary numbers

Read and write numbers in binary, work out how many numbers a set of bits can hold, see why computers are built on switches and logic gates, and trace any data down to its bytes.

Binary numbers in 5 minutes (read before teaching this unit)

The idea in plain words

A bit is one switch that is either off (0) or on (1). Inside a computer a bit is a voltage that is low or high, or a tiny spot magnetised one way or the other. Two states are easy to tell apart reliably, even when the signal is weak or noisy, so computers store everything with them.

To make bigger numbers, put bits side by side. In binary each place is worth double the place on its right: 1, 2, 4, 8, 16, …. Add the places that hold a 1: 10110=16+4+2=2210110 = 16 + 4 + 2 = 22. This is the same idea as place value in base 10, where each column is worth ten times the one on its right.

With nn bits there are 2n2^n different patterns, so they can hold the numbers 00 to 2n−12^n - 1. Four bits hold 0 to 15 (16 patterns); eight bits, a byte, hold 0 to 255. Counting one past the largest number overflows: every bit flips back to 0.

Why it matters

Text, colours, pictures and sound are all stored as numbers, and those numbers as bits. The limits students meet later (colour values stop at 255, a game score wraps round) come straight from counting patterns.

What students get wrong

  • Reading binary as a base-10 number. 101 read as "one hundred and one". Say it digit by digit and add the places.
  • Counting the places from the left. The 1 place is always on the right.
  • Forgetting 0. Four bits make 16 patterns, but the largest number is 15, because one pattern is 0.

Where it comes from

The cards are CS Unplugged's binary numbers activity (csunplugged.org, CC BY-SA 4.0). Doing it with real cards before the board works well.

The words

bit, binary, place value, byte, pattern, overflow.

Cheat sheet: Open to print (A4, with board pictures) · Markdown