Data storage and compression
A byte consists of 8 bits. Larger units are defined using powers of 2, specifically 2^{10}, which equals 1024. It is critical to distinguish between binary prefixes (used in computing) and decimal prefixes (used in some storage marketing).
The standard binary prefixes are:
- Kibibyte (KiB): 2^{10} bytes = 1024 bytes.
- Mebibyte (MiB): 2^{20} bytes = 1024 KiB.
- Gibibyte (GiB): 2^{30} bytes = 1024 MiB.
Note: In many Cambridge contexts, 'KB' is often used loosely to mean Kibibyte (1024 bytes), but strictly speaking, KB can mean 1000 bytes in decimal. Always check the context or use KiB/MiB/GiB for clarity. However, for calculation purposes in this syllabus, always use 1024 as the multiplier/divisor between standard storage units (KB, MB, GB).
| Unit | Definition (Binary) | Equivalent in Bytes |
|---|---|---|
| Bit | Smallest unit of data | 1/8 byte |
| Byte (B) | 8 bits | 1 B |
| Kilobyte (KB/KiB) | 2^{10} bytes | 1024 B |
| Megabyte (MB/MiB) | 2^{20} bytes | 1,048,576 B |
| Gigabyte (GB/GiB) | 2^{30} bytes | 1,073,741,824 B |
\text{Total Bits} = \text{Number of Elements} \times \text{Bits per Element}
Where:
- Number of Elements: For images, this is the total number of pixels (Width \times Height). For sound, this is the total number of samples (Sample Rate \times Duration).
- Bits per Element: This depends on the resolution or depth.
- For images, bits per pixel is determined by the colour depth (e.g., 8-bit colour means 8 bits per pixel). If colour depth is given in bytes, multiply by 8 to get bits.
- For sound, bits per sample is determined by the bit depth (e.g., 16-bit audio means 16 bits per sample).
Once you have the total bits, convert to Bytes by dividing by 8. Then convert to KB, MB, etc., by dividing by 1024 repeatedly.
Step 1: Calculate total pixels.
\text{Pixels} = 1024 \times 768 = 786,432 \text{ pixels}
Step 2: Calculate total bits.
The colour depth is 24 bits per pixel.
\text{Total Bits} = 786,432 \times 24 = 18,874,368 \text{ bits}
Step 3: Convert to Bytes.
\text{Bytes} = \frac{18,874,368}{8} = 2,359,296 \text{ bytes}
Step 4: Convert to Kilobytes (KB).
Using the binary definition (1 \text{ KB} = 1024 \text{ bytes}):
\text{Size in KB} = \frac{2,359,296}{1024} = 2,304 \text{ KB}
Answer: 2304 KB.
Specific Mistake 1: If the colour depth is given as 2 bytes per pixel, students sometimes use '2' directly in the bit calculation. They must multiply by 8 first (2 \times 8 = 16 bits).
Specific Mistake 2: When converting the final answer from Bytes to Kilobytes, some candidates divide by 1000 (decimal) instead of 1024 (binary). Cambridge requires 1024 for storage units.
Correct Approach: Always track your units. If the question asks for bits, leave it in bits. If it asks for KB, ensure you have converted to Bytes first, then divide by 1024.
Why examiners accept this: Examiners look for precise definitions. Simply saying 'making files smaller' is often too vague. You must explicitly mention storage space and/or transmission time.
Correct Usage: "Compression reduces the number of bits required to represent data." OR "The purpose of compression is to reduce file size to save storage space and reduce transmission time over networks with limited bandwidth."
Example Answer: "File compression is the process of reducing the size of a file by encoding information using fewer bits. This is needed to save storage space on devices with limited capacity and to reduce the time taken to transmit files over networks with limited bandwidth."
Data compression is essential because digital media (images, audio, video) contains a vast amount of data. Without compression, storing and transmitting this data would be inefficient.
The primary needs for compression are:
- To save storage space: Hard drives and memory cards have finite capacity. Compression allows more data to be stored in the same physical space.
- To reduce transmission time: Data is sent over networks (internet, Wi-Fi). Networks have a limited bandwidth (data transfer rate). Smaller files take less time to upload and download.
- To lower costs: Storage hardware and data transfer plans often cost more for larger capacities or higher data volumes. Compression reduces these costs.
There are two main types of compression:
Lossless Compression:
- Definition: Compresses data without losing any information. The original data can be perfectly reconstructed from the compressed data.
- How it works: It identifies and removes redundancy (repeated patterns) in the data.
- Methods:
- Run-Length Encoding (RLE): Replaces sequences of identical data values with a count and a single value. For example, 'AAAAA' becomes '5A'.
- Dictionary-based methods (e.g., LZW): Replace repeated occurrences of data patterns with references to a single copy of that pattern.
- Use cases: Text files, executable programs, and images where detail is critical (e.g., PNG, ZIP).
Lossy Compression:
- Definition: Compresses data by permanently removing some information. The original data cannot be perfectly reconstructed.
- How it works: It removes data that is less perceptible to human senses (visual or auditory). This relies on the characteristics of human perception.
- Methods:
- For Images: Reduces colour precision or removes high-frequency details that the eye cannot easily see. For example, JPEG compression groups pixels and averages their colours.
- For Audio: Removes frequencies that are outside the range of human hearing or are masked by louder sounds.
- Use cases: Streaming media, photography, and music where small quality loss is acceptable for much smaller file sizes (e.g., JPEG, MP3).
Why this is wrong: MP3 is a file format that uses lossy compression. It is not the type of compression itself.
Correct Understanding:
- If asked for a type, answer: Lossless or Lossy.
- If asked for an example of lossless compression, you can say Run-Length Encoding (RLE) or ZIP.
- If asked for an example of lossy compression, you can say JPEG or MP3.
Always distinguish between the method (how it works) and the format (the file extension).
Why examiners accept this: Examiners require you to link the technical process to human perception. Simply saying 'it deletes data' is insufficient. You must explain what kind of data is deleted.
Correct Usage: "Lossy compression removes data that is less significant to human perception. For example, in images, it may reduce colour depth or remove high-frequency details that the eye cannot detect. In audio, it removes frequencies outside the audible range."
Example Answer: "Explain how lossy compression works for an image file."
"Lossy compression reduces file size by removing data that is less perceptible to the human eye. This includes reducing the precision of colour values and eliminating high-frequency details that do not significantly affect the visual appearance of the image."