← Teacher guide

Text as numbers

Students type words and read their character codes to see that text is a list of codes, one per character, including spaces, digits and lower case, and that Unicode gives codes to every character (AC9TDI8K03 node 2).

Data representation · Data as numbers · about 35 minutes · Open the student lesson

Classroom resources

Load these into Waypoints Prepare: choose Load URL and paste the copied address, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.

Students will be able to

Timing

Predict and Try 6 min · Worked example 10 min · Vary 9 min · Practise and Make 10 min

Before class

Do the Try board yourself: type a few words, then an emoji.

The one idea: text is a list of character codes, in order. The codes here are ASCII, which Unicode keeps for the first 128 characters; Unicode then gives codes to every script and to emoji. Bytes come up as "0 to 255 fits in one byte"; the binary lessons explain why.

Links: Secret messages (Code pathway) builds ciphers that shift these codes; this lesson is the theory those lessons assume.

Running the lesson

  1. Predict: students who chose 3, 1, 2 used alphabet positions; ask what A's code is.
  2. Try: have everyone type their first name and compare: whose code list is longest?
  3. Worked example: before the 7 line, ask what the digit's code will be.
  4. Vary: ask why the emoji's code is so big.
  5. Make: ask what rule they used to turn capitals into lower case.

The hard part (on purpose)

Students treat a digit in text as an amount (7 stored as 7). Have them type 7 on the board and read the code aloud before the Worked example.

When students get stuck

What you will seeA question to askThe fix
A student writes 7 for the digit 7 (Sam's mistake).What does the board show when you type 7?In text a digit is a character: 0 is 48, so 7 is 55.
A student forgets the space.How many characters are in hi there, counting the gap?The space is a character too: 32.
A student can't find a lower case code.What is the capital's code?Add 32.

Answers to the checks

  1. how is CAB stored?: In text, **A** is stored as 65 and **B** as 66. How is the word **CAB** stored?
    67, 65, 66. Each character has its own code, and the capital letters count on from A = 65, so C is 67. The computer stores only the numbers.
  2. Try: type a word: Type CAB in the box. What numbers are stored?

    C is 67, A is 65, B is 66: one code for each character, in the order you typed them.
  3. Encode Hi 7!: Lower case letters start at a = 97. What number stores lower case **c**?
    99
    a is 97, b is 98, c is 99. Each lower case letter is 32 more than its capital (C is 67).
  4. Find the mistake: Sam stores the text "Year 7" as numbers. Click the line where the working first goes wrong.
    line 4
    Line 4: in text, the 7 is a character like any other, and its code is 55 (the digits start at 0 = 48). 7 is the code for a control character, not the digit.
  5. Capital or lower case?: Why do **A** and **a** have different codes?
    They are different characters, so the computer must be able to tell them apart
    A and a look different and mean different things in passwords and names, so each has its own code. That is why passwords are case sensitive.
  6. Lower case: Type cab in lower case. How did the codes change?

    Each code went up by 32: c is 99, a is 97, b is 98.
  7. One capital: Now type Cab: only the first letter is a capital.

    Only the first code changed back to 67.
  8. A digit: Type just the digit 7.

    The digit 7 is stored as 55. To the computer, a digit in text is a character, not an amount.
  9. A space: Type two words with a space between them, such as hi there.

    The space is stored as 32, between the codes of the two words.
  10. Beyond A to Z: Type an emoji or an accented letter such as é or ñ. What happens to the code?

    These characters have codes too, from Unicode, which gives codes to over a hundred thousand characters. Codes above 255 do not fit in one byte (0 to 255), so they are stored in two to four bytes.
  11. Last letter: Capital letters run from A = 65. What is the code for **Z**?
    90
    65 + 25 = 90.
  12. A list of codes: Which list stores the text **Go 2**?
    71, 111, 32, 50
    G 71, o 111, space 32, digit 2 is 50.
  13. Passwords: Your password is **cat** but you type **Cat**. Why does it fail?
    C is stored as 67 but c is 99, so the codes don't match
    The computer compares codes, and 67 is not 99.
  14. Code to character: What character has the code 97 + 25 = 122?
    z
    97 is a, so 97 + 25 is the 26th lower case letter, z.
  15. Review: same numbers: Review: a text file holds 72, 105. A paint program opens it. What does it show?
    Two shades of grey
    The same numbers, read with a different rule: two dark greys.
  16. change case with numbers: The board shows HI (72, 73). Change only the numbers so the text reads hi in lower case.

    Each lower case letter is 32 more than its capital: 72 + 32 = 104 (h) and 73 + 32 = 105 (i).

Solutions

One possible solution for each task. Other correct programs are fine.

Vary: change one character › Lower case

Open task: any program that does what the step asks.

Vary: change one character › One capital

Open task: any program that does what the step asks.

Vary: change one character › A digit

Open task: any program that does what the step asks.

Vary: change one character › A space

Open task: any program that does what the step asks.

Vary: change one character › Beyond A to Z

Open task: any program that does what the step asks.

change case with numbers

Open task: any program that does what the step asks.

Stretch and support

Stretch: Look up the Unicode code for an emoji you like (or type it on the board). Why do emoji make text messages bigger?

Support: Give the code table: A = 65 … Z = 90, a = 97 … z = 122, 0 = 48 … 9 = 57, space = 32.

Exit ticket

Write the codes for the text Hi 5.

72, 105, 32, 53 (the digit 5 is 48 + 5).

What each step is for

Where it leads

Next: Colour and images (each pixel is numbers).

Where it leads: Secret messages (shifting codes to make a cipher), and the binary lessons (why one byte holds 0 to 255).

Sources