Hello Future Computer Scientists! Let's Master Data Representation!

Welcome to the fascinating world of how computers think! This chapter, Data Representation, is fundamental because everything you see, hear, or type on a computer—from streaming video to a simple text message—must be translated into a language the machine understands.

Don't worry if this sounds tricky! We will break down complex concepts like Binary and Hexadecimal using simple analogies and step-by-step methods. By the end of these notes, you’ll know exactly how 0s and 1s transform into brilliant colour pictures and dynamic music.


Why is Data Representation Important?

The computer's Central Processing Unit (CPU) is built on billions of tiny switches. These switches can only be in two states: ON or OFF. This two-state system is the core of all computing, known as the Binary System (Base 2).


1. The Language of Computers: Binary Basics

1.1 Bits, Bytes, and Beyond

The smallest unit of data is a Bit (short for Binary Digit).

  • A Bit can only be a 0 (OFF) or a 1 (ON).
  • Analogy: Think of a single light switch. It's either on or off—it cannot be half on!
Grouping Bits Together

To store anything useful, bits are grouped:

  • Nibble: 4 bits (Half a byte).
  • Byte: 8 bits (The standard unit for measuring characters, like the letter 'A').

Did you know? Storage capacity is often measured using powers of 2. While 1 Kilobyte (KB) is often approximated as 1,000 bytes, in computer science, it is precisely 1,024 bytes (\(2^{10}\)).

Key Takeaway: All digital information—numbers, text, images, and sound—is stored using combinations of 0s and 1s.


2. Number Systems: Denary, Binary, and Hexadecimal

2.1 Denary (Base 10) vs. Binary (Base 2)

We use the Denary system (Base 10) daily. It uses 10 digits (0–9) and relies on powers of 10 (\(10^0, 10^1, 10^2\), etc.).

The Binary system (Base 2) uses only two digits (0 and 1) and relies on powers of 2.

Converting Binary to Denary (Up to 8 Bits)

To convert an 8-bit binary number to Denary, we use the place value weights:

128   64   32   16   8   4   2   1

Step-by-Step Example: Convert 10110010 to Denary

  1. Write the place values above the binary digits:
    128   64   32   16   8   4   2   1
     1    0    1    1    0    0    1    0
  2. Add up the values where a '1' appears:
    \(128 + 0 + 32 + 16 + 0 + 0 + 2 + 0\)
  3. Calculate the total:
    \(128 + 32 + 16 + 2 = 178\)

So, 10110010 in Binary is 178 in Denary.

Converting Denary to Binary

We use the weighting method (finding the largest power of 2 that fits into the number).

Step-by-Step Example: Convert 201 to Binary

  1. Start with 201. Does 128 fit? Yes (Put a 1).
    \(201 - 128 = 73\)
  2. Does 64 fit into 73? Yes (Put a 1).
    \(73 - 64 = 9\)
  3. Does 32 fit into 9? No (Put a 0).
  4. Does 16 fit into 9? No (Put a 0).
  5. Does 8 fit into 9? Yes (Put a 1).
    \(9 - 8 = 1\)
  6. Does 4 fit into 1? No (Put a 0).
  7. Does 2 fit into 1? No (Put a 0).
  8. Does 1 fit into 1? Yes (Put a 1).
    \(1 - 1 = 0\) (Stop when the remainder is 0)

The resulting 8-bit number is 11001001.

2.2 Hexadecimal (Base 16)

Hexadecimal (Hex) uses 16 symbols: the numbers 0–9 and the letters A–F to represent the Denary values 10–15.

Why use Hexadecimal? It's a huge time-saver! A long string of binary (like 16 bits) is very hard for humans to read and remember. Hex acts as a compact shorthand for binary data.

Since \(2^4 = 16\), 4 bits of binary can be perfectly represented by exactly 1 Hex digit.

Hexadecimal Conversion Table

| Hex | Denary | Binary (4-bit) |

|---|---|---|

| 9 | 9 | 1001 |

| A | 10 | 1010 |

| B | 11 | 1011 |

| F | 15 | 1111 |

Converting Binary to Hexadecimal

This is the easiest conversion! Just group the binary string into 4-bit nibbles, starting from the right.

Step-by-Step Example: Convert 11010110 to Hex

  1. Split the byte into two nibbles: 1101 and 0110.
  2. Convert the first nibble (1101):
    \(8 + 4 + 0 + 1 = 13\). Denary 13 is D in Hex.
  3. Convert the second nibble (0110):
    \(0 + 4 + 2 + 0 = 6\). Denary 6 is 6 in Hex.
  4. Combine the digits: The Hex number is D6.

Quick Review: Conversion between Binary, Denary, and Hex is essential. Practice using the 128-64-32-16-8-4-2-1 table until you can do it quickly!


3. Representing Text and Characters

A computer cannot store the letter 'A' directly. Instead, it stores a binary code that represents 'A'. These codes are defined by standards called Character Sets.

3.1 ASCII (American Standard Code for Information Interchange)

ASCII was one of the first and most widely used character sets. It originally used 7 bits to represent 128 characters (2^7 = 128).

  • This covers all uppercase and lowercase letters, numbers 0–9, and basic punctuation.
  • Example: The capital letter 'A' is represented by the Denary number 65 (01000001 in 8-bit binary).

Common Mistake: Don't confuse the character '1' (which has an ASCII code) with the binary digit 1.

3.2 Unicode

ASCII’s limitation is that it only supports basic English and Western characters.

Unicode was developed to solve this problem. It uses 16 bits or more (up to 32 bits) per character, allowing it to represent millions of unique characters.

  • This includes characters from every world language (Chinese, Arabic, Hindi) and special symbols, including emojis!
  • Benefit: Unicode allows software and web pages to be viewed correctly everywhere in the world, regardless of the language used.

Key Takeaway: ASCII is efficient for English text (8 bits), while Unicode is necessary for global communication and large character sets (16/32 bits).


4. Representing Images (Bitmap)

Most common images (like JPEGs or BMPs) are stored as Bitmaps. Think of a bitmap image as a massive grid of tiny coloured squares.

4.1 Pixels and Resolution

  • A Pixel (Picture Element) is the smallest single dot of colour in a digital image.
  • Resolution refers to the number of pixels in an image, typically measured as Width x Height (e.g., 1920 x 1080).

4.2 Colour Depth

Colour Depth (sometimes called bit depth) is the number of bits used to store the colour information for a single pixel.

The number of possible colours is calculated using the formula: \(2^N\) (where N is the colour depth in bits).

  • 1-bit depth: \(2^1 = 2\) colours (e.g., Black and White).
  • 8-bit depth: \(2^8 = 256\) colours.
  • 24-bit depth: \(2^{24} \approx 16.7\) million colours (known as "True Colour").

Analogy: Colour depth is like the size of your paint palette. A higher bit depth means you have more shades and colours available for your picture.

4.3 Calculating Image File Size (Uncompressed)

To find out how much space an uncompressed bitmap image takes up, use this formula:

$$ \text{File Size (bits)} = \text{Resolution (Width} \times \text{Height)} \times \text{Colour Depth (bits)} $$

Step-by-Step Example: Calculate the size of a 100 x 50 pixel image with a 24-bit colour depth.

  1. Calculate total pixels (Resolution): \(100 \times 50 = 5,000\) pixels.
  2. Calculate total bits: \(5,000 \times 24 \text{ bits/pixel} = 120,000\) bits.
  3. Convert to Bytes (divide by 8): \(120,000 / 8 = 15,000\) bytes.

Key Takeaway: Higher resolution (more pixels) and higher colour depth (more bits per pixel) both lead to a larger file size and better image quality.


5. Representing Sound

Sound in the real world is analogue (smooth, continuous waves). Computers need to convert this into digital data (discrete 0s and 1s) through a process called Sampling.

5.1 The Sampling Process

Sampling is taking measurements of the sound wave's amplitude (loudness) at regular intervals.

Two factors determine the quality and size of the digitized sound:

A. Sample Rate (or Sampling Frequency)

This is the number of samples (measurements) taken per second. It is measured in Hertz (Hz) or kilohertz (kHz).

  • Impact on Quality: A higher sample rate means the computer measures the wave more often, leading to a more accurate representation of the original sound (better quality).
  • Standard Example: CD Quality audio uses a sample rate of 44,100 Hz (44.1 kHz).
B. Bit Depth (or Sample Resolution)

This is the number of bits used to store the amplitude value of each individual sample.

  • Impact on Quality: A higher bit depth allows for a greater range of possible amplitude levels to be recorded, resulting in a more precise and dynamic sound with less background noise.

5.2 Calculating Sound File Size (Uncompressed)

The size of an audio file depends on the duration, the sampling rate, and the bit depth. (Note: This formula assumes mono sound, not stereo.)

$$ \text{File Size (bits)} = \text{Sample Rate (Hz)} \times \text{Bit Depth (bits)} \times \text{Time (seconds)} $$

Step-by-Step Example: Calculate the size (in bytes) of 10 seconds of mono audio sampled at 20,000 Hz with a 16-bit depth.

  1. Calculate total bits:
    \(20,000 \times 16 \times 10 = 3,200,000\) bits.
  2. Convert to Bytes (divide by 8):
    \(3,200,000 / 8 = 400,000\) bytes.

Key Takeaway: Both high sample rate and high bit depth create high-quality audio files, but they also result in much larger file sizes.


Quick Review Summary

| Data Type | Key Concept | Measurement | Impact on File Size |

|---|---|---|---|

| Numbers | Binary (Base 2), Hex (Base 16) | Bits / Bytes | More bits = larger number range |

| Text | Character Sets (ASCII, Unicode) | Bits per character | Unicode (16/32 bits) is larger than ASCII (8 bits) |

| Images | Resolution, Colour Depth | Pixels, Bits per pixel | Higher resolution & depth = larger size |

| Sound | Sample Rate, Bit Depth | Hertz (Hz), Bits per sample | Higher rate & depth = larger size |

You have now covered the essentials of how all information is stored inside a computer! Keep practicing those conversions, and you'll ace this chapter!