← Years 9–10 Data & Information

Run-length encoding: decoding

Decoding run-length data: read each count then its character, and write that character that many times. 3C means CCC and 2D means DD, so 3C2D expands back to CCCDD.

Understanding Run-length encoding: decoding in Years 9–10 Data & Information

What it does: 3C becomes CCC and 2D becomes DD, so the whole code expands to CCCDD. The counts 2 and 5 add to 7, and AABBBBB has exactly 7 characters, so the decode is correct. Each count comes before its character. 3C means CCC and 2D means DD, so the result is CCCDD. Read the count first, then the character it belongs to. 4A is AAAA and 1B is just B. Add up the counts to check the decoded length. 5X gives 5 characters and 3Y gives 3 more, so 8 in total. 12 is a two-digit count, so X is repeated twelve times. 1Y is a single Y. Total length is 12 + 1 = 13.

Common mistakes: The count 2 in 2D means the character D is written two times, so it should be 2D → DD. Writing only one D drops a copy and the decoded text would be too short. In run-length data the count comes first and the character second, so the code should be "3X". "X3" has the pair the wrong way round and would not decode to XXX.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 6–16) and word search (Modules 6–132).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
What does the run-length code 3C2D decode to?
CCDDDCCCDD
Matches
3C2D decoded as CCDDD
↓
The counts were swapped onto the wrong characters. 3C means three Cs and 2D means two Ds, so it should be CCCDD.
Applying
Meanings
Term
3C2D = CCCDD
Meaning
Decoding run-length data: read each count then its character, and write that character that many times. 3C means CCC and 2D means DD, so 3C2D expands back to CCCDD.
Practice
3C2D = CCCDD
Testing
Gaps
3C2D decodes to CCC
Check Answer
Spots
23C → CCC
32D → D

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Coelacanth' badge — Living Fossil, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. What does the run-length code 3C2D decode to?
A. CCDDD
B. CCCDD ✓
Each count comes before its character. 3C means CCC and 2D means DD, so the result is CCCDD.
2. What does the run-length code 4A1B decode to?
A. AAAAB ✓
B. ABBBB
Read the count first, then the character it belongs to. 4A is AAAA and 1B is just B.
3. In the pair 6M, which part tells you how many times to write the letter?
A. The 6, because the count comes first ✓
B. The M, because the letter comes first
In run-length data each pair is a count followed by the character. So 6M decodes to MMMMMM.
4. How long is the decoded text for 5X3Y?
A. 4 characters, the length of the code
B. 8 characters, because 5 + 3 = 8 ✓
Add up the counts to check the decoded length. 5X gives 5 characters and 3Y gives 3 more, so 8 in total.
5. What does 12Z decode to?
A. 12 Zs in a row ✓
B. 2 Zs, because only the last digit counts
A count can have two digits. Read all the digits before the letter, so 12Z means Z written 12 times.

Match the Pairs

4A3B → Decodes to AAAABBB: write A four times, then B three times
12X1Y → Decodes to XXXXXXXXXXXXY: 12 copies of X then one Y, which is 13 characters long
Decoding reads the count first, then the character that gets repeated that many times → 3C2D = CCCDD
To check a decode, add up all the counts: the total must equal the length of the decoded text → 2A5B -> 2 + 5 = 7 characters (AABBBBB)
3C2D decoded as CCDDD → The counts were swapped onto the wrong characters. 3C means three Cs and 2D means two Ds, so it should be CCCDD.
10Z decoded as 1Z and then 0 (Z0) → 10 was read as two separate digits. It is one two-digit count, so 10Z decodes to ZZZZZZZZZZ (ten Zs).

Key Term

3C2D = CCCDD
Decoding run-length data: read each count then its character, and write that character that many times. 3C means CCC and 2D means DD, so 3C2D expands back to CCCDD.

Fill in the Blanks

1. 3C2D decodes to CCCDD
Hint: Type the characters that the pair 2D expands into.
2. In 4A1B, the count for A is 4
Hint: Type the number that comes before the letter A.
3. 3C2D: 3 + 2 = 5 characters when decoded
Hint: Add the counts to get the decoded length.
4. 12X decodes to X repeated 12 times
Hint: Type the whole two-digit count, not just its first digit.
5. In 5Q, the count is 5 and the character is Q
Hint: Type the word for the number part of a pair.

Spot the Error

Question 1
A Decode: 3C2D
B 3C → CCC
C 2D → D
D Result: CCCDD
Line C — The count 2 in 2D means the character D is written two times, so it should be 2D → DD. Writing only one D drops a copy and the decoded text would be too short.
Question 2
A encoded ← "X3"
B count ← 3
C char ← "X"
D decoded ← "XXX"
Line A — In run-length data the count comes first and the character second, so the code should be "3X". "X3" has the pair the wrong way round and would not decode to XXX.
Question 3
A encoded ← 2A3B
B decoded ← AABBB
C length ← 2 * 3
D PRINT length
Line C — The decoded length is the sum of the counts, not their product. It should be 2 + 3 = 5, which matches AABBB. Multiplying gives 6, which is wrong.
Question 4
A encoded ← 12Z
B count ← 1
C char ← "Z"
D decoded ← Z repeated 12 times
Line B — 12Z has a two-digit count. Both digits belong together, so the count is 12, not just the first digit 1. It should be count ← 12.
Question 5
A encoded ← 10A2B
B 10A → AAAAA
C 2B → BB
D length ← 10 + 2
Line B — 10A means ten copies of A, but this line only writes five. It should be 10A → AAAAAAAAAA, with ten As.

Student with a class code? Join your class →