← 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 · How the ideas build

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) · Open in Print · 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) · Open in Print · Markdown

Project briefs

Printable task sheets for assessment or extension: students make something, hand it in and explain their choices. The success criteria are the curriculum nodes' own. Open the briefs page

A badge as numbers (after bits-everywhere)

The club wants a small black and white badge it can save and send as numbers, with no picture file.

Design a badge on an 8 by 8 grid. Turn it into 8 rows of 8 bits, so that someone who only has your numbers can draw it exactly. Then work out how much space it takes, and how much more a colour version of the same badge would take, choosing the three numbers for its main colour.

Hand in:

  • Your badge drawn on an 8 by 8 grid.
  • Your 8 rows of bits, and which bit means black and which means white.
  • A partner's drawing made only from your bits, next to your original.
  • A short explanation of the size in bits and bytes, for black and white and for colour, including the three numbers you chose for the main colour and what colour they make, and one sentence on how a vector version of the badge would be stored instead.

Evidences:

  • Images as pixel colour values (AC9TDI8K03 node 3): Explains that bitmap images store RGB values (0-255) for each pixel; Identifies the colour represented by a given RGB triplet; Describes at least one difference between bitmap and vector image representation
  • Bits, bytes and range (AC9TDI8K04 node 2): States that 1 byte = 8 bits and can represent values from 0 to 255; Does not confuse bit count with the values themselves (e.g. 8 bits does not mean the number 8)

A black and white 8 by 8 badge is 64 bits, which is 8 bytes. In colour, with 24 bits (three numbers from 0 to 255) per pixel, it is 64 pixels × 3 bytes, which is 192 bytes. Look for students who:

  • treat "8 bits" as the number 8, instead of 8 places that can each be 0 or 1 (Bits, bytes and range);
  • reverse a row, or read rows in a different order from the one they wrote;
  • say a colour badge "has more bits" without saying why: each square now needs three numbers.

The partner redraw is the check that the encoding works. When it differs, the fix is usually the order of the bits, which is the point: both sides need the same rule.

A message in bytes (after bits-everywhere)

Write a short message to a partner, but send it only as bytes: eight 0s and 1s for every character.

Choose a message of four to eight characters that has a capital letter, a lower case letter and a space. Turn it into character codes with a code table, then into bytes. Your partner decodes it using the same table. Then explain why your message took the space it did.

Hand in:

  • Your message in plain text, kept secret from your partner until they have decoded theirs.
  • A table with one row per character: the character, its code, and its byte.
  • Your partner's decoded message, and whether it matches.
  • A paragraph that follows one character from the letter, to its code, to its byte, and says what the bytes would mean to a program that treats them as something else.

Evidences:

  • The principle: all data as integers (AC9TDI8K03 node 1): States that all data types are represented as integers in digital systems; Gives at least one example of how a number represents non-numeric information
  • Text as Unicode integers (AC9TDI8K03 node 2): Correctly looks up Unicode values for given characters; Explains that each character has a unique integer in the Unicode set; Encodes at least a short word as a sequence of integers
  • Binary place value and counting (AC9TDI8K04 node 1): Correctly converts at least three decimal numbers to binary; Correctly converts at least three binary numbers to decimal; Explains that each position in a binary number represents a power of 2
  • Binary connects to data encoding (AC9TDI8K04 node 4): Traces a character from text to Unicode value to binary representation; Explains that all data types ultimately become sequences of binary digits; Connects the encoding chain from K03 (data as integers) to K04 (integers as binary)

Students need a code table (the ASCII part of Unicode is enough). A message of 5 characters takes 40 bits, which is 5 bytes: check that this follows from 8 bits per character. Expect the same slips as the lessons: reading the digit 7 as the number seven when its code is 55, and putting the place values in the wrong order. The last handin item is the node's main idea: the same bytes can be read as text, as a colour or as sound, so a number only means something under an agreed encoding.