lnf.cymru stimulus sheet · Computer Science · Year 7

The Gwennol app: icons made of numbers

The app, the school and the pupils on this sheet are invented. The way computers store pictures as numbers is real.

1. The problem

Year 7 at Ysgol Glanrhedyn are designing icons for Gwennol, a homework app. Their teacher, Mrs Jenkins, says: “A computer cannot store a picture. It can only store numbers. Every icon has to become a list of 0s and 1s.” Nia and Harri have drawn some icons. Your job is to turn pictures into numbers, numbers back into pictures, and work out how much space each icon needs.

2. Pixels

A screen picture is made of tiny squares called pixels. The Gwennol icons are 8 pixels wide and 8 pixels high. The number of pixels is like the area of a rectangle: width × height.

3. Black and white icons: 1 bit per pixel

A bit is a single 0 or 1. With 1 bit per pixel, 1 = black ■ and 0 = white □. Each row of the icon becomes 8 bits.

Row: □ □ ■ ■ ■ ■ □ □ Bits: 0 0 1 1 1 1 0 0

4. More colours need more bits

Bits per pixelNumber of coloursWhy
120 or 1
2400, 01, 10, 11
38000 up to 111
416Each extra bit doubles the number of colours.

The Gwennol 4-colour code (2 bits per pixel)

Code00011011
ColourWhite (W)Yellow (Y)Green (G)Orange (O)

5. How much space does an icon need?

Number of pixels = width × height Number of bits = number of pixels × bits per pixel Number of bytes = number of bits ÷ 8 (8 bits = 1 byte)

6. Run-length encoding: a shorter way to write a row

Instead of writing every pixel, count how many of the same colour come in a run. W means white and B means black.

Row: □ □ ■ ■ ■ ■ □ □ Bits: 00111100 (8 characters) Runs: 2W4B2W (6 characters)

7. The icons

Icon A: Harri’s “home” icon, as bits (1 bit per pixel)

Row 1: 00011000 Row 2: 00111100 Row 3: 01111110 Row 4: 11111111 Row 5: 01000010 Row 6: 01011010 Row 7: 01011010 Row 8: 01111110

Icon B: Nia’s “favourites” icon, as a picture (1 bit per pixel)

□□□□□□□□
□■■□□■■□
■■■■■■■■
■■■■■■■■
□■■■■■■□
□□■■■■□□
□□□■■□□□
□□□□□□□□

Icon C: the “spring” icon, 4 by 4 pixels, 4-colour code

Row 1: 00 01 01 00 Row 2: 01 11 11 01 Row 3: 00 01 01 00 Row 4: 10 10 10 10