GCSE · Computer Science · AQA · Spec 8525

Convert character code to character

Secret message: 71 111 52 105 116. It's a real word, and every number is the code for one character. Let's decode it.

Decode a hidden word

71 111 52 105 116 — what does it say?

Every character has a number, called its character code. Here is part of a code table (these are the codes ASCII uses): 52 → 4 · 55 → 7 · 71 → G · 72 → H · 79 → O · 105 → i · 111 → o · 116 → t. The program hands each code to CODE_TO_CHAR, which looks it up and gives back one character. Step through and watch the word appear.

Before each Next, find the code in the table and say the character it will give back.

1 word ← ""
2 word ← word + CODE_TO_CHAR(71)
3 word ← word + CODE_TO_CHAR(111)
4 word ← word + CODE_TO_CHAR(52)
5 word ← word + CODE_TO_CHAR(105)
6 word ← word + CODE_TO_CHAR(116)
7 OUTPUT word
code incharacter outword
""

Output

 

Step 1: word starts empty. Nothing has been converted yet.

1 / 7

Use Next and Back to step. Each row shows the code that went in and the character that came out.

Step 1 of 7: word starts empty. Nothing has been converted yet..

Watch out: Code 52 gives back the character 4, not the number 4. It is text, exactly like the G before it.

Predict, then check

Commit to an answer before you reveal it.

A program runs d ← CODE_TO_CHAR(55). The code table says 55 → 7. What is stored in d?

Spot the slip

The letter after G

This program should output the letter that comes after G in the code table (71 → G, 72 → H). It doesn't. Which line goes wrong?

A student's program — which line goes wrong?

Your turn to write it

Three letters from one code

A variable start holds the character code of a capital letter. Write pseudo-code, or code in a programming language you have studied, that outputs that letter followed by the next two letters in the code table, all on one line. For example, with the table 80 → P, 81 → Q, 82 → R, a start of 80 should output PQR. [3 marks]

0 words · your answer stays on this page and is not sent anywhere.

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

What you need to know

  • Every character has a whole-number character code, listed in a code table.
  • Converting a character code to a character gives back the one character that code stands for, e.g. CODE_TO_CHAR(71) or chr(71) gives G.
  • The result is always a character, which is text, even when that character is a digit such as 7.
  • To reach a different character, do the arithmetic on the code first, then convert: CODE_TO_CHAR(code + 1).

The big picture

Converting a character code to a character is a string handling operation: you give it a whole-number code and it gives back the one character that code stands for in the character set's code table. In pseudo-code it is often written CODE_TO_CHAR(code); in Python it is chr(code). The result is always a character, even when it is a digit, so any arithmetic must be done on the code before converting.

Key points

1Code in, character out: the operation takes a number and returns exactly one character.
2Upper- and lower-case letters have different codes, so 111 gives o while 79 gives O.
3A digit character is text: CODE_TO_CHAR(55) gives the character 7, which cannot be used in a sum as the number 7.
4Adding 1 to the converted character does not give the next letter; add 1 to the code, then convert.
5The opposite operation, converting a character to its character code, is a separate operation (ord() in Python).

Worked example

Problem

Use this code table: 65 → A, 66 → B, 67 → C, 68 → D. What does this program output? n ← 65 n ← n + 2 c ← CODE_TO_CHAR(n) OUTPUT c + c

⚠ Watch out

Thinking that converting a code for a digit gives you the number. CODE_TO_CHAR(55) gives the character 7, which is text, so joining it to the character 1 makes the text "71" rather than adding up.

🧠

Memory hook

Number in, character out, and once it's a character the maths is over.

✓

Check yourself

Using the table 104 → h and 105 → i, what does OUTPUT CODE_TO_CHAR(104) + CODE_TO_CHAR(105) display, and why is the answer not a number?

Flashcards

(6)
What goes in and what comes out when you convert a character code to a character?
A whole-number character code goes in; the one character that code stands for in the code table comes out.
How is this operation written in Python, and in pseudo-code?
chr(code) in Python, often CODE_TO_CHAR(code) in pseudo-code. For example chr(71) gives 'G'.
With the table 52 → 4, is CODE_TO_CHAR(52) the number 4?
No. It is the character 4, which is text and cannot be used in a sum as the number 4.
Does code 111 give a capital O or a lower-case o?
Lower-case o. Capital O is a different character with its own code, 79.
With 71 → G and 72 → H, how do you get H from the code 71?
Add 1 to the code first, then convert: CODE_TO_CHAR(71 + 1) gives H.
What is the name of the operation that goes the other way?
Convert character to character code, which is ord() in Python.

Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.

Learning with Lightbulb is opening soon

You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.

Keep me posted

More AQA GCSE Computer Science topics

See the full AQA Computer Science curriculum →

How this lesson was checked. This AQA GCSE Computer Science (specification 8525)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 30 September 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.