← Data representation

Bits all the way down

Every kind of data ends up as bits: a character becomes its code, and the code becomes 8 bits (A is 65, which is 01000001). A pixel is three codes, so 24 bits. The chain is always the same: data, then numbers, then binary.

You now know how text, pictures and sound become numbers, and how numbers become bits. What does the letter A actually look like inside the computer?

The data lessons showed that text, pictures and sound are all stored as numbers. The binary lessons showed how a number is stored as bits. Put the two together and every piece of data is a chain: data → number → bits. Eight bits make a byte, which holds 0 to 255: one character code, one colour amount or one sound sample.

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

The letter A

The letter **A** has the code 65. How is it stored in the computer's memory?

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

Try: one byte for A

Was your prediction right? The leading 0 keeps every character the same length: 8 bits.

Try it yourselfYour edits are saved in this browser.

Set the eight cards to 65, the code for A. What pattern of bits is it?

Use the board. This ticks when you get there.

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

Worked example: trace the chain

Worked exampleBefore each step, say what you think comes next.
  1. A→65\text{A} \to 65Text: the character's code.

Now count the bits in a pixel.

One pixel is three numbers (red, green, blue), each one byte. How many **bits** is one pixel?

Sam works out how many bits the word cat takes. Click the line where it first goes wrong.

The byte **01000001** is in memory. What does it mean?

ModifyChange the problem on purpose and see what happens.

Vary: one letter at a time

Try it yourselfYour edits are saved in this browser.

The cards show 72, the code for H. Make 73, the code for I.

Use the board. This ticks when you get there.

Now make 104, the code for lower case h. Which card did you have to add?

Use the board. This ticks when you get there.

Make 255, a colour amount at full.

Use the board. This ticks when you get there.

Make 128, a sound sample at the middle (silence).

Use the board. This ticks when you get there.

Make 32, the code for a space.

Use the board. This ticks when you get there.

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

Bytes and bits

How many bits does the word **hello** take, at one byte a character?

A 2 × 2 picture, three bytes a pixel. How many bytes?

Music often uses 65 536 levels a sample. How many bytes is each sample?

As text, which character is the byte **01000010**?

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

A lower case letter

Then write your initials as bytes.

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

Capital A is 65. Lower case letters are 32 more.

Another hint

97 = 64 + 32 + 1.

Another hint

Turn up the 64, 32 and 1 cards.

The number is hidden. Set the cards to the byte for lower case a.

Use the board. This ticks when you get there.

For teachers

Students trace characters, colours and sound samples from data to numbers to bytes on eight binary cards, closing the loop between data representation and binary (AC9TDI8K04 node 4). About 35 minutes.

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

Students will be able to

Before class

The integration node (the kit calls it the cross-standard point between K03 and K04): students assemble data → number → binary for two kinds of data.

Simplification: text here is one byte a character (ASCII). Unicode characters beyond 255 take two to four bytes (Text as numbers).

Running the lesson

  1. Predict: students who chose 65 or A haven't joined the two halves yet; the Try does it.
  2. Worked example: ask what the 24 bits of a black pixel look like.
  3. Vary: ask why lower case is always the 32 card added.
  4. Make: have students write their initials as bytes on paper.

The hard part (on purpose)

Students think a character is one bit. Ask how many different things one bit can be (two), then how many characters there are.

When students get stuck

Stretch and support

Stretch: A phone photo is about 4000 × 3000 pixels. Roughly how many bytes before compression? (36 million.) Why do we need compression?

Support: Keep the 128 64 32 16 8 4 2 1 card values written above the board.

Where it leads

This closes the Data representation course.

Next (Years 9–10): Making data smaller (compression). Code links: Secret messages shifts these codes; colour values in turtle are these bytes.

What each step is for

Now you can
You reached the endBack to Data representation