Welcome to Data Representation: Text, Sound, and Images!
Hello IGCSE students! This chapter is really exciting because it answers a fundamental question: How does a computer, which only understands 0s and 1s, manage to store your favourite songs, text messages, and high-definition photos?
Everything a computer processes—whether it’s a letter, a musical note, or a shade of blue—must first be converted into binary. We will look at the specific methods used for text, sound, and images, and learn how big these files get and why we need to make them smaller!
1. Representing Text (Character Sets)
1.1 Why Text Needs to be Binary
When you type the letter 'A' on your keyboard, the computer doesn't see a shape; it sees a sequence of 0s and 1s. A character set is essentially a predefined list that maps every letter, number, and symbol to a unique binary code. Think of it like a code book or an alphabet that the computer uses.
1.2 Character Set Standards: ASCII and Unicode
There are two main standards you need to know:
(i) ASCII (American Standard Code for Information Interchange)
- Bits Required: Originally 7 bits, later extended to 8 bits.
- Maximum Characters: Using 8 bits, it can represent \(2^8 = 256\) unique characters.
- Usage: This is enough for the English alphabet (upper and lower case), numbers (0-9), and common symbols (like @, %, $).
(ii) Unicode
- The Problem with ASCII: 256 characters isn't enough for all the world's languages (e.g., Chinese, Arabic, or even emojis).
- The Solution: Unicode was developed to solve this problem. It uses significantly more bits per character (often 16 or 32 bits).
- Greater Range: Because it uses more bits, Unicode can represent a vastly greater range of characters and symbols, including nearly every written language and modern emojis.
- Trade-off: The disadvantage is that Unicode files take up more storage space than ASCII files because each character requires more bits.
More bits = More characters available (like Unicode) = Larger file size.
2. Representing Sound
2.1 Converting Analogue Sound to Digital
Sound in the real world is analogue—it's a continuous wave. Computers, however, only understand digital data (0s and 1s). To store sound, we must convert the continuous analogue wave into discrete digital measurements. This process is called sampling.
Step-by-Step Sampling Process:
- The analogue sound wave is measured at regular intervals.
- The height (amplitude) of the wave at each interval is recorded.
- These measurements are converted into binary values.
- The computer processes and stores this binary data.
2.2 Key Factors Affecting Sound Quality and File Size
Two factors determine the accuracy (quality) and the file size of the digital sound recording:
(i) Sample Rate (Frequency)
- Definition: The number of samples taken per second. It is measured in Hertz (Hz) or kilohertz (kHz).
- Analogy: Imagine taking photos of a rapidly moving object. The faster you take the photos (higher sample rate), the more detail you capture of the movement.
- Effect: A higher sample rate means the digital recording is a closer match to the original analogue sound, leading to higher quality and a larger file size.
(ii) Sample Resolution (Bit Depth)
- Definition: The number of bits used to store the value of each sample.
- Analogy: This is like how many levels of volume (0 to 100, or 0 to 65,535) you can record.
- Effect: A higher sample resolution (more bits per sample) allows for a finer, more accurate measurement of the sound amplitude, leading to higher quality and a larger file size.
To improve sound quality, you must increase both the Sample Rate AND the Sample Resolution. Both actions increase the file size.
3. Representing Images
3.1 Pixels and Binary Conversion
A digital image (like a JPEG or PNG) is made up of millions of tiny squares called pixels (short for Picture Elements).
Each pixel holds a colour value. When the image is stored, the computer converts the colour value of every single pixel into binary.
3.2 Key Factors Affecting Image Quality and File Size
Two main factors determine the quality and storage requirements of an image:
(i) Resolution
- Definition: The number of pixels in the image (often expressed as Width x Height).
- Example: A screen resolution of 1920 x 1080 means there are 1920 pixels across and 1080 pixels down.
- Effect: A higher resolution means more pixels are used to capture detail, resulting in higher quality and a larger file size.
(ii) Colour Depth (Bit Depth)
- Definition: The number of bits used to represent the colour of each individual pixel.
- Analogy: If your colour depth is 1 bit, you can only have 2 colours (\(2^1\))—usually black and white. If your colour depth is 24 bits, you can have over 16 million colours (\(2^{24}\)).
- Effect: A higher colour depth means the image can display a greater range of colours, leading to higher quality and a larger file size.
4. Data Storage and File Size Calculations
4.1 Data Storage Measurement Units (1.3.1)
When calculating file size, it's essential to know the standard units and the correct conversion factor (which is 1024, not 1000, for KiB, MiB, etc.).
- bit: A single binary digit (0 or 1).
- nibble: 4 bits.
- byte: 8 bits.
- kibibyte (KiB): 1024 bytes.
- mebibyte (MiB): 1024 KiB.
- gibibyte (GiB): 1024 MiB.
- tebibyte (TiB): 1024 GiB.
To convert from bits to Bytes, you divide by 8.
To convert from Bytes to KiB, MiB, GiB, etc., you divide by 1024 for each step up.
4.2 Calculating Image File Size (1.3.2)
The total file size (in bits) is found by multiplying the total number of pixels by the colour depth.
Image File Size Formula:
\[File\ Size\ (bits) = Resolution\ (Width \times Height)\ \times\ Colour\ Depth\ (bits\ per\ pixel)\]
(In plain terms: File Size = Total Pixels multiplied by Bits per Pixel)
Step-by-Step Example:
An image has a resolution of 100 x 50 pixels and a colour depth of 8 bits.
- Calculate Total Pixels: \(100 \times 50 = 5000\) pixels.
- Calculate Total Bits: \(5000 \times 8 = 40000\) bits.
- Convert to Bytes: \(40000 \div 8 = 5000\) Bytes.
- Convert to KiB: \(5000 \div 1024 \approx 4.88\) KiB.
4.3 Calculating Sound File Size (1.3.2)
The size of a recorded sound file depends on the Sample Rate, Sample Resolution, and how long the sound lasts (length of track).
Sound File Size Formula:
\[File\ Size\ (bits) = Sample\ Rate\ \times\ Sample\ Resolution\ \times\ Length\ of\ Track\ (seconds)\]
(In plain terms: File Size = Samples per Second multiplied by Bits per Sample multiplied by Time in Seconds)
Step-by-Step Example:
A 10-second sound clip is recorded with a Sample Rate of 44,100 Hz and a Sample Resolution of 16 bits.
- Calculate Total Bits: \(44100 \times 16 \times 10 = 7,056,000\) bits.
- Convert to Bytes: \(7056000 \div 8 = 882,000\) Bytes.
5. Data Compression
5.1 The Purpose and Need for Compression (1.3.3)
Data compression is the process of reducing the size of a file. Why do we need it?
- Less Bandwidth Required: Smaller files mean data can be transmitted across networks (like the internet) much faster.
- Less Storage Space Required: You can fit more files onto your hard drive, SSD, or memory stick.
- Shorter Transmission Time: Quicker downloads and uploads.
5.2 Types of Compression: Lossy vs. Lossless (1.3.4)
(i) Lossy Compression
- Definition: Lossy compression permanently removes data from the file to reduce its size. This data loss is usually data that humans are unlikely to notice (like very high audio frequencies or subtle colour variations).
- Effect: It achieves the greatest reduction in file size, but you cannot restore the file back to its original quality.
-
Examples:
- Reducing the colour depth or resolution of an image.
- Reducing the sample rate or resolution of a sound file.
- Common file types: JPEG (images), MP3 (audio), MPEG (video).
(ii) Lossless Compression
- Definition: Lossless compression reduces file size by identifying and removing redundancy (repeated patterns) in the data without permanently losing any information.
- Effect: The original data can be perfectly reconstructed from the compressed file. The file size reduction is not as dramatic as lossy compression.
- Example Technique: Run Length Encoding (RLE). RLE works well for images with large areas of the same colour (like cartoons or flags). Instead of storing "White, White, White, White, Black, Black," it stores "(4 White), (2 Black)".
- Example: If an image file contains 100 white pixels in a row, RLE stores this as the colour (White) and the count (100).
LossLess = Look for patterns, Loss is not permanent (like ZIP files).
LossY = Data is forever gone (like MP3).