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 in | character out | word |
|---|---|---|
| "" |
Output
Step 1: word starts empty. Nothing's been converted yet.
Use Next and Back to step. Each row shows the code that went in and the character that came out.
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?
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
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?
How do you write this operation in Python, and in pseudo-code?
With the table 52 → 4, is CODE_TO_CHAR(52) the number 4?
Does code 111 give capital O or lower-case o?
With 71 → G and 72 → H, how do you get H starting from the code 71?
What's the operation that goes the other way?
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 postedMore AQA GCSE Computer Science topics
- Authentication routines
- Boolean data type
- Character data type
- Concept of a data type
- Concept of subroutines
- Constant declaration
- Convert character to character code
- Correcting errors
- Data validation routines
- Equal to (relational operator)
- Greater than (relational operator)
- Greater than or equal to (relational operator)
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.