← IGCSE Computer Science Paper 1

Encoding and decoding a small colour image

A table giving each colour a binary code. Write each pixel's code row by row to encode an image; read the codes back to redraw it. 4 colours need 2 bits.

Understanding Encoding and decoding a small colour image in IGCSE Computer Science Paper 1

What it does: 2 bits can make 2 x 2 = 4 different values. These are exactly the four codes needed to give 4 colours their own code. A grid 4 pixels wide and 3 rows tall has 12 pixels. Each pixel uses a 2-bit code, so 12 x 2 = 24 bits. Read each 2-bit code in order and look it up in the colour code table: 01 = red, 00 = white, 11 = black, 10 = blue. Red is 01 and white is 00, so the row is 01 01 00. 10 is blue, not red. Reading the codes back in pairs gives 00 white, 11 blue, 00 white, 11 blue, so the row can be redrawn on the grid.

Common mistakes: 1 bit only gives 2 codes (0 and 1), so it can't store 4 colours. 4 colours need 2 bits per pixel. In the colour code table red is 10, not 11 (11 is blue). The row should be 01 10.

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 43–58) and word search (Modules 28–58).

Take this worksheet further — free with Cloodit

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

Learning
Duo
A small image uses 4 colours. How many bits are needed for each pixel's colour code?
2 bits per pixel4 bits per pixel
Matches
0 = white, 1 = black, 0 = red, 1 = blue
↓
Only 1 bit is used, so there are just 2 codes (0 and 1). The codes repeat and the colours cannot be told apart. 4 colours need 2 bits.
Applying
Meanings
Term
colour code table
Meaning
A table giving each colour a binary code. Write each pixel's code row by row to encode an image; read the codes back to redraw it. 4 colours need 2 bits.
Practice
00 = white
Testing
Gaps
4 colours need bits for each pixel
Check Answer
Spots
1Colours needed: 4
2Bits per pixel: 1

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

The 'Walrus' badge — Method Master, 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. A small image uses 4 colours. How many bits are needed for each pixel's colour code?
A. 4 bits per pixel
B. 2 bits per pixel ✓
2 bits give 2^2 = 4 different codes: 00, 01, 10, 11. That is exactly enough for 4 colours.
2. Using the table 00 = white, 01 = red, 10 = blue, 11 = black, which row of 4 pixels is encoded as 01 00 11 10?
A. red, white, black, blue ✓
B. white, red, blue, black
Read each 2-bit code in order and look it up in the colour code table: 01 = red, 00 = white, 11 = black, 10 = blue.
3. How do you encode a small image into binary?
A. Write the binary number of the total pixel count and nothing else
B. Look up each pixel's colour in the table and write its code, row by row ✓
Each pixel's colour is replaced by its code from the colour code table. The codes are written in order, row by row.
4. A 3 x 2 image (3 pixels wide, 2 rows) uses 2-bit colour codes. How many bits does the binary data use in total?
A. 12 bits ✓
B. 6 bits
The image has 3 x 2 = 6 pixels. Each pixel needs 2 bits, so 6 x 2 = 12 bits.
5. An image needs 5 different colours. Which colour depth is the smallest that works?
A. 3 bits per pixel ✓
B. 2 bits per pixel
2 bits only give 4 codes, which is not enough. 3 bits give 2^3 = 8 codes, so 3 bits is the smallest that covers 5 colours.

Match the Pairs

01 10 10 01 → A row of 4 pixels: black, red, red, black (table: 00 white, 01 black, 10 red, 11 blue)
00 11 00 11 → A row of 4 pixels: white, blue, white, blue (table: 00 white, 01 black, 10 red, 11 blue)
An image with 4 colours needs 2 bits per pixel, so its colour code table has four different codes → 00, 01, 10, 11
To find the size of an encoded image, multiply the pixels in the grid by the bits per pixel → 4 pixels x 3 rows x 2 bits = 24 bits
0 = white, 1 = black, 0 = red, 1 = blue → Only 1 bit is used, so there are just 2 codes (0 and 1). The codes repeat and the colours cannot be told apart. 4 colours need 2 bits.
0110 = white, black, black, white → The code was read 1 bit at a time. With a 2-bit table the bits must be read in pairs: 01 10 is black, red.

Key Term

colour code table
A table giving each colour a binary code. Write each pixel's code row by row to encode an image; read the codes back to redraw it. 4 colours need 2 bits.

Fill in the Blanks

1. 4 colours need 2 bits for each pixel
Hint: Type the number of bits that gives enough different codes for 4 colours.
2. table: 00=white, 01=red, 10=blue, 11=black row 1: red, blue, white code: 01 10 00
Hint: Look up the colour in the table and type its 2-bit code for the middle pixel.
3. table: 00=white, 01=red, 10=blue, 11=black row: 11 01 00 colours: black, red, white
Hint: Decode the middle code by reading the table backwards to find its colour.
4. 5 colours need 3 bits for each pixel
Hint: Type the smallest number of bits that gives at least 5 different codes.
5. 4 pixels x 2 bits = 8 bits in each row
Hint: Type the result of multiplying the pixels in a row by the bits per pixel.

Spot the Error

Question 1
A Colours needed: 4
B Bits per pixel: 1
C 00=white 01=black
D 10=red 11=blue
Line B — 1 bit only gives 2 codes (0 and 1), so it can't store 4 colours. 4 colours need 2 bits per pixel.
Question 2
A 00=white 01=black
B 10=red 11=blue
C Row 1: black red = 01 11
Line C — In the colour code table red is 10, not 11 (11 is blue). The row should be 01 10.
Question 3
A Table: 10=red, 11=blue
B Red pixel is 11
C Blue pixel is 11
Line B — The colour code table says red is 10. 11 is the code for blue.
Question 4
A 00=white 01=black
B 10=red 11=blue
C Row 2: blue blue white red
D Binary: 11 11 10 00
Line D — The codes must follow the pixel order. The third pixel is white (00) and the fourth is red (10), so it should be 11 11 00 10.
Question 5
A 00=white 01=black 10=red
B Code: 01 00 10
C Row 1: black red white
Line C — Decoding reads the codes in order: 01 is black, 00 is white, 10 is red. The row should be black white red.

Student with a class code? Join your class →