Decoding run-length counts back into pixels

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Decoding run-length counts back into pixels

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A row is 5 pixels wide and its counts are 3, 2. Which row do you get? (W = white, B = black)
A BBBWW
B WWWBB
2. A row is 6 pixels wide and its counts are 0, 4, 2. Which row do you get?
A BBBBWW
B WWWWBB
3. What does a first count of 0 tell you when decoding?
A The row is empty
B The row starts with black
4. You have just written the pixels for one count. What do you do for the next count?
A Switch to the other colour
B Keep using the same colour
5. A grid is 8 pixels wide. A row has the counts 3, 2, 2. Does this row add up?
A No, it adds up to 7, so 1 pixel is missing
B Yes, it adds up to 8

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
13,2,3 (8 wide) AThe row was started with black. The first count is always white unless it is 0. It should be WWBBBW.
24 + 2 + 2 = 8 BOnly 2 white pixels were written at the end instead of 3, so the row has 7 pixels, not 8. It should be WWWBBWWW.
3Start with white, then take turns between colours: 2 white, 3 black, 1 white CDecodes to WWWBBWWW: 3 white, then 2 black, then 3 white
4A row that starts with black has a first count of 0 white pixels DA check that the counts add up to the grid width of 8 pixels
5Counts 2,3,1 on a 6-wide row decoded as BBWWWB E0,3,3 = BBBWWW
6Counts 3,2,3 on an 8-wide row decoded as WWWBBWW F2,3,1 = WWBBBW

Definitions

run-length decoding

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
Counts 3, 2, 1 -> ___BBW
2.
Counts 0, 2, 3 -> __WWW
3.
Counts 4, 3, 1: 4 + 3 + 1 = _ pixels
4.
Width 6, counts 5, _ add up to 6
5.
W = white, B = black Counts 2, 1, 2 -> WW_WW

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A Counts: 3, 2, 3 (width 8)
B 3 white: WWW
C 2 white: WW
D 3 white: WWW
E Row: WWWBBWWW
Question 2
A Start with black
B Counts: 2, 4, 2
C WW BBBB WW
D Total: 2+4+2 = 8 pixels
Question 3
A Counts: 0, 3, 4
B 0 white: (none)
C 3 white: WWW
D 4 white: WWWW
E Row: BBBWWWW (width 7)
Question 4
A Width: 6
B Counts: 0, 2, 3
C Row: BBWWW
D Check: 0+2+3 = 5
Question 5
A Counts: 4, 1, 3
B Row: WWWBWWWW
C Check: 4+1+3 = 8
D Width: 8 pixels

Answer Key

Decoding run-length counts back into pixels
Section A: Quick Questions
Q1
B — WWWBB
Q2
A — BBBBWW
Q3
B — The row starts with black
Q4
A — Switch to the other colour
Q5
A — No, it adds up to 7, so 1 pixel is missing
Section B: Match the Pairs
Q1
3,2,3 (8 wide) → Decodes to WWWBBWWW: 3 white, then 2 black, then 3 white
Q2
4 + 2 + 2 = 8 → A check that the counts add up to the grid width of 8 pixels
Q3
Start with white, then take turns between colours: 2 white, 3 black, 1 white → 2,3,1 = WWBBBW
Q4
A row that starts with black has a first count of 0 white pixels → 0,3,3 = BBBWWW
Q5
Counts 2,3,1 on a 6-wide row decoded as BBWWWB → The row was started with black. The first count is always white unless it is 0. It should be WWBBBW.
Q6
Counts 3,2,3 on an 8-wide row decoded as WWWBBWW → Only 2 white pixels were written at the end instead of 3, so the row has 7 pixels, not 8. It should be WWWBBWWW.
Section C: Definitions
Q1
run-length decoding — Turn counts back into pixels: write that many of one colour, then that many of the other, taking turns, until the row is full. Start with white. A first count of 0 means the row starts black.
Section D: Fill in the Blanks
Q1
Counts 3, 2, 1 -> WWWBBW
Q2
Counts 0, 2, 3 -> BBWWW
Q3
Counts 4, 3, 1: 4 + 3 + 1 = 8 pixels
Q4
Width 6, counts 5, 1 add up to 6
Q5
W = white, B = black Counts 2, 1, 2 -> WWBWW
Section E: Spot the Error
Q1
C — Decoding takes turns between colours. After 3 white comes black, so line 3 should be '2 black: BB'.
Q2
A — Decoding always starts with white. Only a first count of 0 means the row starts black. Here the first count is 2, so start with white.
Q3
C — The first count 0 means no white pixels, so the colours take turns and the next 3 pixels are black. Line 3 should be '3 black: BBB'.
Q4
A — The counts 0+2+3 add up to 5, and the decoded row has 5 pixels. So the width must be 5, not 6.
Q5
B — The counts say 4 white, 1 black, then 3 white. The broken row has 3 white, 1 black, then 4 white. It should be WWWWBWWW.