1.3 Data storage and compression

Binary Prefixes

1. The Two Standards

Historically, the term "Kilobyte" was used to mean 1024 bytes. However, to stay consistent with scientific SI units, the IEC (International Electrotechnical Commission) introduced specific Binary Prefixes.

Metric (SI) Units

Based on Powers of 10. Used by drive manufacturers and in networking.

103 = 1,000

Example: Kilobyte (kB)

Binary (IEC) Units

Based on Powers of 2. Used by Operating Systems and for RAM.

210 = 1,024

Example: Kibibyte (KiB)

2. The Binary Prefix Table

For the IGCSE exam, you must use the 1024-based names when referring to memory sizes.

Unit Name Abbreviation Value (Bytes) Power of 2
Kibibyte KiB 1,024 210
Mebibyte MiB 1,048,576 220
Gibibyte GiB 1,073,741,824 230
Tebibyte TiB 1,099,511,627,776 240
Pebibyte PiB 1,125,899,906,842,624 250

3. Smallest Units of Data

  • Bit: A single 0 or 1. (Short for Binary Digit).
  • Nibble: A group of 4 bits.
  • Byte: A group of 8 bits. (The standard unit for one character of text).

4. Conversion Formulas

Exam Tip: When calculating data sizes, always multiply or divide by 1024, not 1000.
Smaller to Larger Larger to Smaller
Divide by 1024 Multiply by 1024
(e.g., KiB to MiB) (e.g., GiB to MiB)

Example Calculation:

How many MiB are in 2 GiB?

$2 \times 1024 = 2048 \text{ MiB}$

Data Compression

1. Why Compress Data?

Compression is the process of reducing the size of a file. This is crucial for several reasons:

  • Faster Transmission: Files take less time to upload/download or send via email.
  • Storage Savings: More files can be stored on a drive (SSD/HDD).
  • Streaming: Required for smooth video (YouTube/Netflix) and music streaming.
  • Website Speed: Smaller images help web pages load faster.

2. Lossy vs. Lossless Compression

Lossy

Permanently removes "unnecessary" data that the human eye or ear cannot easily perceive.

File size: Significantly reduced.

Formats: JPEG, MP3, MP4.

Lossless

Reduces file size without losing any original data. The file can be reconstructed exactly.

File size: Moderately reduced.

Formats: PNG, GIF, ZIP, FLAC.

3. How Lossless Works (RLE)

One common method of lossless compression is Run-Length Encoding (RLE). It looks for consecutive repeating data and stores it as a single value and a count.

Uncompressed Data:
AAAAABBBCCCDDDDD

RLE Compressed:
5A3B3C5D

In images, RLE works by identifying long runs of identical colored pixels.

4. How Lossy Works

Lossy compression algorithms use Perceptual Coding:

  • Images (JPEG): Reduces the number of colors or simplifies areas where the eye won't notice a change.
  • Sound (MP3): Removes frequencies that the human ear cannot hear and removes quieter sounds that are "masked" by louder sounds.

5. Comparison Summary

Feature Lossy Lossless
Original Quality Lost permanently Kept perfectly
Compression Ratio Very High (Tiny files) Low (Larger files)
Best for... Photos, Video, Streaming Text files, Spreadsheets, Code
⚠️ Exam Note: You cannot use Lossy compression for software programs or text files. If you lose even one bit of a program's code, the entire program may fail to run!