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 crack it.

Decode a hidden word

71 111 52 105 116 — what does it say?

Every character has a number, called its character code. Here's 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'll 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's 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's been converted yet..

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

Predict, then check

Pick one before you reveal. No peeking.

A program runs d ← CODE_TO_CHAR(55). The code table says 55 → 7. What's sitting in d now?

Find the faulty line

The letter after G

This program should output the letter 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 its own whole-number character code, and a code table lists them.
  • Converting a character code to a character is a string handling operation: number in, one character out.
  • Pseudo-code often writes it CODE_TO_CHAR(code). Python writes it chr(code), so chr(71) gives G.
  • Have a goYour code table says 33 → !. Write the Python call that hands you back the character !.

    chr(33)

    chr() takes the code, which is a number; writing chr("!") would be handing it the very character you were trying to get.

  • Case matters: capital and lower-case letters have different codes, so 79 gives O but 111 gives o.
  • Have a goSam is completely certain that CODE_TO_CHAR(104) gives capital H: "it's the same letter!" The table says 72 → H and 104 → h. Who wins the argument?

    Not Sam: 104 gives lower-case h.

    H and h are different characters with different codes; 104 is the code for h, and capital H would need 72.

  • What comes back is always a character, which is text, even when it's a digit like 7.
  • A digit character can't be used in a sum as its number: in Python, chr(55) + 1 stops with an error.
  • Put + between two characters and they join up into longer text rather than adding.
  • Have a goTable: 51 → 3 and 52 → 4. Commit first: does CODE_TO_CHAR(51) + CODE_TO_CHAR(52) give 7, 103, or something else?

    Something else: the text "34".

    Both results are characters, so + joins them; 7 treats them as numbers, and 103 adds codes the program no longer holds.

  • Need a different character? Do the maths on the code first, then convert: CODE_TO_CHAR(code + 1).
  • Going the other way, character to code, is a separate operation (ord() in Python).

The big picture

Converting a character code to a character is a string handling operation. Hand it a whole-number code and it hands back the one character that code stands for in the code table. Pseudo-code often writes it CODE_TO_CHAR(code); Python writes it chr(code). What comes back is always a character, even when it's a digit, so any maths has to happen on the code before you convert.

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 can't be used in a sum as the number 7.
4Adding 1 to the converted character doesn't give the next letter; add 1 to the code, then convert.
5Converting a character to its character code is a separate operation going the other way (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 the code for a digit gives you the number. It looks convincing. It isn't: CODE_TO_CHAR(55) gives the character 7, which is text, so joining it to the character 1 makes the text "71" instead of 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 isn't the answer a number?

Flashcards

(6)
Converting a character code to a character: what goes in, and what comes out?
A whole-number character code goes in. The one character that code stands for in the code table comes out.
How do you write this operation in Python, and in pseudo-code?
chr(code) in Python; often CODE_TO_CHAR(code) in pseudo-code. So chr(71) gives 'G'.
With the table 52 → 4, is CODE_TO_CHAR(52) the number 4?
No. It's the character 4: text, which can't be used in a sum as the number 4.
Does code 111 give capital O or 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 starting from the code 71?
Add 1 to the code first, then convert: CODE_TO_CHAR(71 + 1) gives H.
What's 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 October 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.