← Data representation

Everything is numbers

A computer stores text, pictures and sound all as numbers. The same numbers mean different things depending on how a program reads them: 72 is the letter H to a text program, a dark grey to a paint program and a sound level to a music program.

A message, a photo and a song all end up in the same computer memory. What is actually stored there?

Everything a computer stores, whether a message, a photo or a song, is stored as numbers. A number on its own does not say what it is. A program has to read it with a rule, called an encoding: a text program reads each number as a letter, a paint program as a colour, a music program as a sound level.

PredictRead the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.

One file, two programs

A file holds three numbers: 72, 105, 33. A text program opens it and shows **Hi!**. A paint program opens the same file. What does it show?

TryTry it on the board and compare the result with your prediction.

Try: read the same numbers

Now try Sound and All three. The top row never changes.

Try it yourselfYour edits are saved in this browser.

The board reads 72, 105, 33 as text. Switch it to read them as grey shades. Did the numbers change?

Use the board. This ticks when you get there.

InvestigateWork out why it happens, one step at a time.

Worked example: one number, three meanings

Worked exampleBefore each step, say what you think comes next.
  1. 7272The number stored. It is the same in every row.

Now read 255 as a shade.

A paint program reads numbers as grey shades from 0 (black) to 255 (white). What does it show for 255?

Sam reasons about a file holding 72, 105, 33. Click the line where the reasoning first goes wrong.

Which of these is an example of a number standing for something that is not a number?

ModifyChange the problem on purpose and see what happens.

Vary: change one number

Try it yourselfYour edits are saved in this browser.

Make the first number 255. What happens in each row?

Use the board. This ticks when you get there.

Now make the first number 0.

Use the board. This ticks when you get there.

Make the first number 74. What letter is it? (H is 72.)

Use the board. This ticks when you get there.

Make all three numbers 128. What does the sound row show?

Use the board. This ticks when you get there.

Make the first number 10. What does the text row show?

Use the board. This ticks when you get there.

PractiseA few on your own, to check you have it.

Which rule?

In text, A is stored as 65 and the letters go in order. What number stores C?

A music program opens a text file. What will you most likely hear?

A grey shade of 0 is…

Why does a file need to say what kind of data it holds (for example .txt or .png)?

MakeMake your own problem using what you have learned. Expect a few tries; that is normal.

Write a word

Then switch the reading: what does your word look like as grey shades, and as sound?

Try it yourselfYour edits are saved in this browser.
Need a hint?

Capital letters start at A = 65 and go in order. Lower case starts at a = 97.

Another hint

Y is the 25th letter, so its code is 65 + 24 = 89.

Another hint

e is 97 + 4 = 101 and s is 97 + 18 = 115.

Change the three numbers so the text reads Yes (capital Y, then lower case e and s).

Use the board. This ticks when you get there.

For teachers

Students switch one set of numbers between text, grey shades and sound to see that all data is stored as numbers and that an encoding gives the numbers their meaning (AC9TDI8K03 node 1). About 35 minutes.

Open the teacher guide: answers, solutions, slides and a worksheet.

Students will be able to

Before class

Try the board yourself first: switch between Text, Grey shades and Sound.

The one idea (the kit's hinge for AC9TDI8K03): every kind of data is stored as integers, and an encoding (the rule a program reads them with) gives them meaning. The next three lessons look at each encoding properly (text codes, RGB pixels, sound samples); then the binary lessons show how each number is stored.

Simplifications to say out loud if asked: text codes here are ASCII (A = 65); real text uses Unicode, which includes the same codes for these letters. Real pictures use three numbers per pixel (red, green, blue), not one grey. Real sound uses many thousands of samples a second.

Running the lesson

  1. Predict: students who chose "the letters drawn as a picture" think the letters are stored. Ask what the computer actually has.
  2. Try: ask whether the top row changed when they switched.
  3. Worked example: before each line, ask what 72 will be under the next rule.
  4. Vary: ask why 10 shows nothing as text but a fine shade as grey.
  5. Make: have students check their word as shades and as sound.

The hard part (on purpose)

Students think the letters or colours are in the file and the numbers are a translation. Keep pointing at the top row: that is all the computer has; the rows below are what programs make of it.

When students get stuck

Stretch and support

Stretch: Open any small image or text file in a hex viewer (or ask the teacher to show one). Can you find the letter codes in a text file?

Support: Give a short code table (A = 65 … Z = 90, a = 97 … z = 122) for Make.

Where it leads

Next: Text as numbers (character codes and Unicode).

Where it leads: images as RGB pixels and sound as samples (the rest of AC9TDI8K03), then binary: how each number is stored with only 0 and 1.

What each step is for

Now you can
Next lesson2. Text as numbersText is stored as a list of numbers, one for each character. Every character has its own code: A is 65, a is 97, a space is 32 and even the digit 7 has a code (55). Unicode gives codes to over a hundred thousand characters, including emoji.