Specialty Digest

Global English editionLearners’ Study Dashboard — in development
The Knowledge Library for All

Online Courses / University Track / Computing Foundations

Module 2 · Lesson 3 · Core

Representing text: character codes

See how letters, digits and symbols become numbers, and then bits, through a code table.

  • 50 minutes
  • Serves O2
  • Assumes M2.L2

Phase 1: Prepare

Step 1 Warm-up recall

From M2.L2: convert 5 to binary.

Private: nothing you type here is sent or stored.

Step 2 Learning goal

By the end of this lesson you can:

  • explain why text needs a code table (Foundation);
  • encode a short word using ASCII codes (Core);
  • estimate the size of a plain text message (Core).

Phase 2: Teach

Step 3 A familiar example

A computer stores only numbers. So how does it store the letter A? Only by agreement: everyone uses the same table that says which number stands for which character.

Step 4 Clear explanation

A character code is an agreed table that gives each character a number. The classic table is ASCII (American Standard Code for Information Interchange), which covers English letters, digits and common punctuation with codes 0 to 127. In ASCII the capital letter A is 65, B is 66 and so on, the lower-case a is 97, and the digit character 0 is 48. Unicode is a much larger table that covers the writing systems of the world; its first 128 codes match ASCII.

CharacterHCode72Bits01001000
Storing text: each character is looked up in a table of codes, and the code is stored as bits.
CharacterCode (decimal)Code (8 bits)
H7201001000
i10501101001
A6501000001
a9701100001

The word “Hi” is therefore stored as the codes 72 and 105, which are the two bytes 01001000 and 01101001. Plain English text stored with one byte for each character takes one byte per character, so a message of 12 characters, including spaces, takes 12 bytes. Some Unicode encodings, such as UTF-8, use one to four bytes per character, so text in other scripts can take more space. The point of the lesson: the bits are the same, and only the agreed table makes them mean text. See also the entry on the programming language, which uses such codes for strings.

Step 5 Worked example (4 marks)

Encode the word “Hi” in ASCII bits (H = 72, i = 105).

  1. Convert 72: 64 + 8 gives 01001000. (1 mark)
  2. Convert 105: 64 + 32 + 8 + 1 gives 01101001. (1 mark)
  3. Join the bytes: 01001000 01101001. (1 mark)
  4. Size: 2 characters = 2 bytes = 16 bits. (1 mark)

Phase 3: Practise

Step 6 Learner practice (instant-marked)

1. A character code is:

2. In ASCII, the capital letter A has the code:

3. A 12-character plain English message at one byte per character takes:

4. Unicode differs from ASCII mainly because it:

Phase 4: Close

Step 7 Recap

  • A code table maps characters to numbers; the numbers are stored as bits.
  • ASCII: A = 65, a = 97, digit 0 = 48.
  • Plain English text at one byte per character takes one byte per character.

Step 8 Exit ticket (ungraded)

Write the ASCII codes of the letters B and b, given that A is 65 and a is 97.

Private: nothing you type here is sent or stored.

Step 9 Go further (Extension)

Look up the code of one non-English letter in Unicode and note how many bytes it takes in UTF-8.

Common mistakes

MistakeWhy it fails
Treating the digit character 5 as the number 5The character 5 has its own code.
Forgetting spaces count as charactersCount every character.
Assuming one byte per character everywhereOther scripts can need more.

Limits. This lesson simplifies Unicode; it does not cover how encodings such as UTF-8 are constructed.