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.
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.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
3C2D = CCCDDFill in the Blanks
Spot the Error
Student with a class code? Join your class →