Year 10 · Computer Science · Autumn 1
Data representation · Lesson 5 of 5
Compression and the exam questions
Exam practice1.3 Data storage and compression
Year 10 · Computer Science · Data representation · Lesson 5 of 5
You will learn to
- Explain why files are compressed: to save storage space and to send them faster.
- Compare lossy and lossless compression, with an example file type for each.
- Use run-length encoding (RLE) on a string of data and work out the space saved.
- Answer past-paper questions on topic 1, using the command word to shape each answer.
Year 10 · Computer Science · Data representation · Lesson 5 of 5
Success criteria
You have got it when you can say:
- I can encode a short string with RLE and say how many bytes it saves.
- I can choose lossy or lossless for a photo, a text file and a program, and say why.
- I can mark my own answer with the mark scheme and find the missing point.
Year 10 · Computer Science · Data representation · Lesson 5 of 5
Retrieval starter
Questions from before. Write your answers, then show them.
- Last lesson
In 8-bit two's complement, 11111111 is…
A −127B 255C −1
C. −1
- Earlier this unit
Which of these is lossy?
A PNGB JPEGC ZIP
B. JPEG
Year 10 · Computer Science · Data representation · Lesson 5 of 5
Key words (1 of 3)
- Bit
- A single binary digit, 0 or 1.
- Nibble
- A group of 4 bits, which matches one hexadecimal digit.
- Byte
- A group of 8 bits.
- Character set
- A list of characters a computer can use, each with its own binary code.
Year 10 · Computer Science · Data representation · Lesson 5 of 5
Key words (2 of 3)
- Sample rate
- The number of sound samples taken each second, measured in hertz (Hz).
- Sample resolution
- The number of bits used to store each sound sample.
- Pixel
- The smallest single-coloured square in a bitmap image.
- Image resolution
- The number of pixels in an image, often written as width × height.
Year 10 · Computer Science · Data representation · Lesson 5 of 5
Key words (3 of 3)
- Colour depth
- The number of bits used to store the colour of each pixel.
- Lossy compression
- Making a file smaller by permanently removing some data.
- Lossless compression
- Making a file smaller without losing any data, so the original can be rebuilt exactly.
- Run-length encoding (RLE)
- A lossless method that stores each run of repeated values as a count and the value.
The explanation · step 1 of 9 · part 1 of 3
Units of data
A bit is one 0 or 1. A nibble is 4 bits. A byte is 8 bits.
After the byte, each unit is 1024 times bigger than the one before.
1024 is used because it is a power of 2: 2¹⁰ = 1024. Computers count in powers of 2.
Try the toy: type 1 and choose GiB. Read the MiB and KiB rows in the table. How many times did you multiply by 1024 to reach KiB?
The explanation · step 1 of 9 · part 2 of 3
Units of data (continued)
| Unit | Equal to | In bytes |
|---|---|---|
| 1 nibble | 4 bits | half a byte |
| 1 byte (B) | 8 bits | 1 |
| 1 kibibyte (KiB) | 1024 bytes | 1,024 |
| 1 mebibyte (MiB) | 1024 KiB | 1,048,576 |
| 1 gibibyte (GiB) | 1024 MiB | 1,073,741,824 |
| 1 tebibyte (TiB) | 1024 GiB | about 1.1 million million |
| 1 pebibyte (PiB) | 1024 TiB | 2⁵⁰ |
| 1 exbibyte (EiB) | 1024 PiB | 2⁶⁰ |
The explanation · step 1 of 9 · part 3 of 3
Units of data (continued)
Cambridge uses 1024, not 1000. Shops often say KB, MB and GB meaning 1000. In the exam, always use 1024 and the KiB, MiB, GiB names.
There is something to try for this step in the IGCSE library.
The explanation · step 2 of 9 · part 1 of 2
Converting between units
Going to a smaller unit: multiply (× 1024, or × 8 from bytes to bits).
Going to a bigger unit: divide (÷ 1024, or ÷ 8 from bits to bytes).
Move one unit at a time and write each step. It is slower but it avoids mistakes.
The explanation · step 2 of 9 · part 2 of 2
Converting between units (continued)
Paper 1 has no calculator. Exam numbers are usually chosen so that dividing by 8 and 1024 comes out neatly.
The explanation · step 2 of 9
The maths: Changing units
The explanation · step 3 of 9 · part 1 of 3
Calculating image file size
Every pixel needs the same number of bits: the colour depth.
So file size in bits = number of pixels × colour depth. Number of pixels = width × height.
Then divide by 8 for bytes, by 1024 for KiB, and by 1024 again for MiB.
Real files are a little bigger, because they also store extra data such as the width and height.
The explanation · step 3 of 9 · part 2 of 3
Calculating image file size (continued)
The explanation · step 3 of 9 · part 3 of 3
Calculating image file size (continued)
Do not forget to divide by 8. Pixels × colour depth gives bits, not bytes.
The explanation · step 4 of 9 · part 1 of 3
Calculating sound file size
Each second you take (sample rate) samples. Each sample uses (sample resolution) bits.
So file size in bits = sample rate × sample resolution × length in seconds.
Then divide by 8 for bytes and by 1024 for KiB or MiB, as for images.
This is for one channel (mono). Change minutes into seconds first.
The explanation · step 4 of 9 · part 2 of 3
Calculating sound file size (continued)
The explanation · step 4 of 9 · part 3 of 3
Calculating sound file size (continued)
A length of 2 minutes is 120 seconds. Using 2 in the formula is a very common lost mark.
The explanation · 5 more steps
More on the lesson page
The lesson page has the rest of the explanation, step by step:
- Why we compress files
- Lossy compression
- Lossless compression
- Run-length encoding (RLE)
- RLE: working out the saving
Year 10 · Computer Science · Data representation · Lesson 5 of 5
Try it: Run-length encoder
Year 10 · Computer Science · Data representation · Lesson 5 of 5
The maths: How much did compression save?
Symbols first, then the words, then the equation. Change the numbers.
Year 10 · Computer Science · Data representation · Lesson 5 of 5
Quick quiz · 1 of 3
A 10 × 10 image at 8 bits per pixel takes…
- A 8,000 bits
- B 800 bits = 100 bytes
- C 80 bytes
B. 800 bits = 100 bytes
10 × 10 × 8 = 800 bits. Divide by 8 for bytes.
Year 10 · Computer Science · Data representation · Lesson 5 of 5
Quick quiz · 2 of 3
How many bits are in a byte?
- A 16
- B 4
- C 8
C. 8
A byte is 8 bits. 4 bits is a nibble.
Year 10 · Computer Science · Data representation · Lesson 5 of 5
Quick quiz · 3 of 3
Hex B2 in binary is…
- A 1100 0010
- B 1011 0010
- C 1011 0100
B. 1011 0010
B = 11 = 1011 and 2 = 0010. One hex digit is 4 bits.
Year 10 · Computer Science · Data representation · Lesson 5 of 5
Exit ticket
Answer on paper before you go. Then check.
Adding 11001100 and 01011010 in an 8-bit register gives…
A 11111111B An overflow errorC 00100110 with no problem
B. An overflow error The true answer needs 9 bits (100100110). The ninth bit does not fit.
Shifting 00001010 (10) one place left gives…
A 00010100 (20)B 00001011 (11)C 00000101 (5)
A. 00010100 (20) A left shift doubles. 10 becomes 20.
Year 10 · Computer Science · Data representation · Lesson 5 of 5
Homework and the challenge
Homework
The CS 1 quiz.
End-of-unit challenge
End-of-unit test: past-paper questions on topic 1 (about 25 marks, 25 minutes).