Chapter 1: Data Representation – GCE/IGCSE CS Notes


Number Systems, Text, Sound, Images & Compression

Based on Cambridge O Level Computer Science 2210 Syllabus (2026-2028)


1. Introduction to Number Systems

Why Do Computers Use Binary?

Computers use binary because their internal components (transistors) operate in two states:

  • ON (1) – electricity flowing
  • OFF (0) – no electricity

All forms of data (text, images, sound) must be converted to binary to be processed by a computer.

The Three Main Number Systems

Number SystemBaseDigits UsedUsed By
Binary20, 1Computers
Denary (Decimal)100–9Humans
Hexadecimal160–9, A–FProgrammers

Key Terms:

  • Bit: A single binary digit (0 or 1)
  • Nibble: 4 bits
  • Byte: 8 bits

2. Binary (Base-2)

Understanding Binary

Binary is a base-2 number system. Each digit represents a power of 2, starting from the right (position 0).

Place Values in Binary (8-bit)

Bit Position76543210
Power of 22⁷2⁶2⁵2⁴2⁰
Value1286432168421

Binary to Denary Conversion

Method: Multiply each binary digit by its place value and add the results.

Example 1: Convert 1011 to denary

Bit Position3210
Binary Digit1011
Calculation1×2³0×2²1×2¹1×2⁰
Value8021

Total = 8 + 0 + 2 + 1 = 11

Example 2: Convert 11010110 to denary (8-bit)

Position76543210
Binary11010110
Value128640160420

Total = 128 + 64 + 16 + 4 + 2 = 214


3. Denary (Base-10)

Denary to Binary Conversion

Method 1: Division by 2 (Repeated)

  • Divide the number by 2 repeatedly
  • Record the remainder (0 or 1)
  • Read remainders from bottom to top (last to first)

Example 1: Convert 13 to binary

DivisionQuotientRemainder
13 ÷ 261 (LSB)
6 ÷ 230
3 ÷ 211
1 ÷ 201 (MSB)

Binary = 1101 (Read from bottom up: 1,1,0,1)

Example 2: Convert 214 to binary

DivisionQuotientRemainder
214 ÷ 21070
107 ÷ 2531
53 ÷ 2261
26 ÷ 2130
13 ÷ 261
6 ÷ 230
3 ÷ 211
1 ÷ 201

Binary = 11010110 (8 bits)

Method 2: Subtraction Method

  • Find the largest power of 2 ≤ the number
  • Subtract it and put 1 in that position
  • Repeat with remainder

For 13:

  • Largest power ≤ 13 is 8 (2³) → put 1 in position 3, remainder = 5
  • Largest power ≤ 5 is 4 (2²) → put 1 in position 2, remainder = 1
  • Largest power ≤ 1 is 1 (2⁰) → put 1 in position 0, remainder = 0
  • Positions 1 gets 0
  • Result: 1,1,0,1 → 1101

4. Hexadecimal (Base-16)

Understanding Hexadecimal

Hexadecimal is base-16, using digits 0-9 and letters A-F.

Denary0-9101112131415
Hex0-9ABCDEF

Why Do Programmers Use Hexadecimal?

  1. Compact Representation: Much shorter than binary
  • Binary: 1101001110101101 (16 digits)
  • Hex: D3AD (4 digits)
  1. Easy to Read: Humans find hex easier to understand
  2. Easier to Program
  3. Easier to debug
  4. Direct Binary Mapping: 1 hex digit = exactly 4 bits (nibble)
  5. Common Uses in Computer Science:
  • Memory addresses (e.g., 0xFF5733)
  • Colour codes in web design (e.g., #FF5733)
  • MAC addresses
  • Assembly language programming
  • Debugging and low-level systems

Denary to Hexadecimal Conversion

Method: Repeated division by 16, recording remainders.

Example 1: Convert 47 to hexadecimal

DivisionQuotientRemainder
47 ÷ 16215 → F (LSB)
2 ÷ 1602 → 2 (MSB)

Hexadecimal = 2F

Example 2: Convert 214 to hexadecimal

DivisionQuotientRemainder
214 ÷ 16136 → 6
13 ÷ 16013 → D

Hexadecimal = D6

Hexadecimal to Denary Conversion

Method: Multiply each digit by its place value (16ⁿ) and add.

Example 1: Convert 2F to denary

DigitPositionValueCalculation
216¹22 × 16 = 32
F (15)16⁰1515 × 1 = 15

Total = 32 + 15 = 47

Example 2: Convert D6 to denary

DigitPositionValueCalculation
D (13)16¹1313 × 16 = 208
616⁰66 × 1 = 6

Total = 208 + 6 = 214

Binary to Hexadecimal Conversion

Method: Split binary into groups of 4 bits (nibbles) from the right, then convert each group.

Example 1: Convert 11010110 to hexadecimal

Binary:   1101 0110
Groups:   [1101] [0110]
Convert:   D      6

Hexadecimal = D6

Example 2: Convert 1011101011 to hexadecimal (10 bits)

  • Add leading zeros to make complete nibbles: 0010 1110 1011
  • Groups: 0010 (2), 1110 (14→E), 1011 (11→B)
  • Hexadecimal = 2EB

Hexadecimal to Binary Conversion

Method: Convert each hex digit to its 4-bit binary equivalent.

Example 1: Convert 3F to binary

3 → 0011
F → 1111
Result: 00111111

Example 2: Convert A7 to binary

A (10) → 1010
7 → 0111
Result: 10100111

Quick Reference Table

DenaryBinary (4-bit)Hex
000000
100011
200102
300113
401004
501015
601106
701117
810008
910019
101010A
111011B
121100C
131101D
141110E
151111F

5. Binary Addition & Overflow

Adding Two 8-bit Binary Integers

Rules of Binary Addition:

  • 0 + 0 = 0 (carry 0)
  • 0 + 1 = 1 (carry 0)
  • 1 + 0 = 1 (carry 0)
  • 1 + 1 = 0 (carry 1)
  • 1 + 1 + 1 = 1 (carry 1)

Example 1: Add 00110101 (53) and 00011010 (26)

   00110101
+  00011010
  ---------
   01001111  (79)

Example 2: Add 01100101 (101) and 00111010 (58)

   01100101
+  00111010
  ---------
   10011111  (159)

Understanding Overflow

What is Overflow?

  • Overflow occurs when the result of a calculation is too large to fit in the available number of bits
  • For 8-bit registers, the maximum value is 255 (11111111)
  • If the result exceeds 255, an overflow error occurs

Why Does Overflow Happen?

  • Computers have a predefined limit (e.g., 8-bit, 16-bit registers)
  • When a value outside this limit needs to be stored, the computer cannot represent it correctly

Example of Overflow:

Add 11001000 (200) and 00111000 (56)

   11001000
+  00111000
  ---------
  100000000 (256 - needs 9 bits!)

In an 8-bit register, we would only keep the last 8 bits: 00000000 (0)
This is incorrect! The actual answer should be 256.

Detecting Overflow:

  • In 8-bit addition, overflow occurs when there is a carry into the 9th bit
  • The result would require more than 8 bits to represent correctly

6. Logical Binary Shifts

What is a Logical Binary Shift?

A logical binary shift moves all bits in a binary number left or right by a specified number of positions.

Key Rules:

  • Bits shifted from the end are lost (discarded)
  • Zeros are shifted in at the opposite end
  • Multiple shifts can be performed

Logical Left Shift

Effect: Each left shift multiplies the number by 2

Example 1: Left shift 00001101 (13) by 1 position

Original:  00001101  (13)
Left shift 1: 00011010  (26)

13 × 2 = 26 ✓

Example 2: Left shift 00001101 (13) by 2 positions

Original:    00001101  (13)
Left shift 2: 00110100  (52)

13 × 4 = 52 ✓

Example 3: Left shift with loss of significant bits

Original:    11010011  (211)
Left shift 1: 10100110  (166 - lost the leading 1)

Note: The most significant bit (MSB) was lost, changing the value significantly.

Logical Right Shift

Effect: Each right shift divides the number by 2 (integer division, remainder lost)

Example 1: Right shift 00001101 (13) by 1 position

Original:     00001101  (13)
Right shift 1: 00000110  (6)

13 ÷ 2 = 6.5 → integer division gives 6 ✓

Example 2: Right shift 00001101 (13) by 2 positions

Original:     00001101  (13)
Right shift 2: 00000011  (3)

13 ÷ 4 = 3.25 → integer division gives 3 ✓

Example 3: Right shift with loss of bits

Original:     00110101  (53)
Right shift 3: 00000110  (6 - lost the last 3 bits)

53 ÷ 8 = 6.625 → integer division gives 6 ✓

Summary of Effects

Shift TypeDirectionMathematical EffectBits Lost
Logical LeftMultiply by 2ⁿMost significant bits
Logical RightDivide by 2ⁿLeast significant bits

7. Two’s Complement (Signed Binary)

Why Two’s Complement?

So far, we’ve only represented positive binary numbers. Two’s complement allows us to represent both positive and negative integers in binary.

Range of Two’s Complement 8-bit Numbers

  • Minimum: -128 (10000000)
  • Maximum: +127 (01111111)
  • Total range: -128 to +127 (256 values)

Representing Positive Numbers

Positive numbers in two’s complement are represented exactly the same as normal binary, but the most significant bit (MSB) must be 0.

Example: +13 in two’s complement

  • Binary of 13: 00001101 (MSB is 0, so it’s positive)

Representing Negative Numbers

Method 1: Convert from Positive to Negative

Steps:

  1. Write the positive number in binary
  2. Invert all bits (0→1, 1→0)
  3. Add 1 to the result

Example 1: Find two’s complement of -13

Step 1: +13 in binary = 00001101
Step 2: Invert bits = 11110010
Step 3: Add 1 = 11110011

Therefore, -13 in two’s complement = 11110011

Example 2: Find two’s complement of -42

Step 1: +42 in binary = 00101010
Step 2: Invert bits = 11010101
Step 3: Add 1 = 11010110

Therefore, -42 in two’s complement = 11010110

Method 2: Convert from Negative to Positive (Reverse Process)

Steps to find the value of a negative two’s complement number:

  1. Invert all bits
  2. Add 1
  3. Convert to denary and add negative sign

Example: What is 11110011 in denary?

Step 1: Invert bits = 00001100
Step 2: Add 1 = 00001101
Step 3: Convert to denary = 13, so value = -13

Two’s Complement Conversion Table

DenaryTwo’s Complement
+12701111111
+100000001
000000000
-111111111
-211111110
-12810000000

Recognizing Positive vs Negative

  • MSB = 0 → Positive number (or zero)
  • MSB = 1 → Negative number

8. Text Representation

Why Convert Text to Binary?

Computers can only process binary, so all text characters must be converted to binary codes.

Character Sets

A character set is a table that maps each character to a unique binary code.

ASCII (American Standard Code for Information Interchange)

  • Uses 7 or 8 bits per character
  • Can represent 128 or 256 characters
  • Includes:
  • Uppercase letters (A-Z)
  • Lowercase letters (a-z)
  • Digits (0-9)
  • Punctuation marks
  • Control characters (space, enter, tab)

Example ASCII values:

  • ‘A’ = 65 (binary 01000001)
  • ‘a’ = 97 (binary 01100001)
  • ‘0’ = 48 (binary 00110000)
  • Space = 32 (binary 00100000)

Unicode

  • Uses more bits per character (usually 16 or 32)
  • Can represent over 1 million characters
  • Includes characters from:
  • All world languages
  • Emojis 😊
  • Special symbols (©, ®, ∞)

Why Unicode?

  • ASCII only covers English and basic symbols
  • Unicode allows for international text representation
  • Different languages, emojis, and special symbols can be represented

Comparison:

FeatureASCIIUnicode
Bits per character7-816-32
Maximum characters256Over 1 million
Language supportEnglish onlyAll languages
Emoji supportNoYes
File sizeSmallerLarger

9. Sound Representation

How Sound is Stored in Binary

Sound waves are analogue (continuous). To store them digitally, they must be converted to binary through a process called sampling.

The Sampling Process

  1. Sample – Take measurements of the sound wave at regular intervals
  2. Quantize – Convert each measurement to a binary number
  3. Store – Save the binary values

Sample Rate

  • Definition: The number of samples taken per second
  • Unit: Hertz (Hz) or kilohertz (kHz)
  • Example: 44.1 kHz = 44,100 samples per second

Effect of Higher Sample Rate:

  • ✅ More accurate representation of the original sound
  • ✅ Better quality recording
  • ❌ Larger file size
  • ❌ More processing power needed

Sample Resolution (Bit Depth)

  • Definition: The number of bits used to store each sample
  • Example: 16-bit resolution = each sample stored as a 16-bit number

Effect of Higher Sample Resolution:

  • ✅ More precise measurements (more possible values)
  • ✅ Better dynamic range (quieter to louder sounds)
  • ✅ Better quality recording
  • ❌ Larger file size

Relationship Between Sample Rate, Resolution and Quality

Sample RateResolutionQualityFile Size
Low (8 kHz)Low (8-bit)Poor (like telephone)Small
Medium (22 kHz)Medium (16-bit)Good (FM radio)Medium
High (44.1 kHz)High (16-bit)Excellent (CD quality)Large
Very High (96 kHz)High (24-bit)Studio qualityVery Large

10. Image Representation

How Images are Stored in Binary

Images are stored as a grid of tiny squares called pixels (picture elements).

Resolution

  • Definition: The number of pixels in an image
  • Expression: Width × Height
  • Example: 1920 × 1080 = 2,073,600 pixels (about 2 megapixels)

Effect of Higher Resolution:

  • ✅ More detail in the image
  • ✅ Sharper image
  • ❌ Larger file size
  • ❌ More processing power needed

Colour Depth

  • Definition: The number of bits used to represent each pixel’s colour
  • Also called: Bit depth
  • Formula: Number of colours = 2^colour depth

Common Colour Depths:

Colour DepthNumber of ColoursUse Case
1-bit2 (black and white)Simple graphics
4-bit16Early computer graphics
8-bit256GIF images
16-bit65,536Medium quality
24-bit16.7 millionTrue colour (photos)
32-bit4.3 billionHigh-end graphics (+alpha channel)

Effect of Higher Colour Depth:

  • ✅ More accurate colours
  • ✅ Smoother gradients
  • ❌ Larger file size

Relationship Between Resolution, Colour Depth and Quality

ResolutionColour DepthQualityFile Size
Low (640×480)Low (8-bit)Blocky, limited coloursSmall
Medium (1280×720)Medium (16-bit)Good for webMedium
High (1920×1080)High (24-bit)Photo qualityLarge
Very High (4K)High (24-bit)ProfessionalVery Large

11. Data Storage Measurement

Units of Storage

Computers measure data storage in powers of 2 (based on binary). The prefix “kibi” means 1024, not 1000.

UnitAbbreviationSizeApproximate
BitbSmallest unit1 or 0
Nibble4 bitsHalf a byte
ByteB8 bits1 character
KibibyteKiB1024 bytes1024 characters
MebibyteMiB1024 KiB~1 million characters
GibibyteGiB1024 MiB~1 billion characters
TebibyteTiB1024 GiB~1 trillion characters
PebibytePiB1024 TiB~1 quadrillion characters
ExbibyteEiB1024 PiB~1 quintillion characters

Conversion Rules

To convert from larger to smaller: Multiply by 1024

Example: 2 MiB to KiB = 2 × 1024 = 2048 KiB

To convert from smaller to larger: Divide by 1024

Example: 4096 KiB to MiB = 4096 ÷ 1024 = 4 MiB

Important Notes

  • In computer science (for storage), 1 KiB = 1024 bytes (not 1000)
  • For data transmission speeds, sometimes 1000 is used (kbps = kilobits per second)
  • Always use 1024 for storage calculations unless the question specifies otherwise

12. File Size Calculations

Image File Size Formula

Formula:

File Size (bits) = Width × Height × Colour Depth
File Size (bytes) = (Width × Height × Colour Depth) ÷ 8

Example 1: Calculate file size of a 1920 × 1080 image with 24-bit colour

Size in bits = 1920 × 1080 × 24
             = 2,073,600 × 24
             = 49,766,400 bits

Size in bytes = 49,766,400 ÷ 8
              = 6,220,800 bytes

Size in KiB = 6,220,800 ÷ 1024 = 6,075 KiB
Size in MiB = 6,075 ÷ 1024 = 5.93 MiB

Example 2: Calculate file size of a 800 × 600 image with 8-bit colour

Size in bits = 800 × 600 × 8
             = 480,000 × 8
             = 3,840,000 bits

Size in bytes = 3,840,000 ÷ 8 = 480,000 bytes
Size in KiB = 480,000 ÷ 1024 = 468.75 KiB

Sound File Size Formula

Formula:

File Size (bits) = Sample Rate × Sample Resolution × Channels × Duration (seconds)
File Size (bytes) = (Sample Rate × Sample Resolution × Channels × Duration) ÷ 8

Note: Stereo sound has 2 channels, mono has 1 channel.

Example 1: Calculate file size of a 60-second stereo recording

  • Sample Rate: 44,100 Hz
  • Sample Resolution: 16 bits
  • Channels: 2 (stereo)
  • Duration: 60 seconds
Size in bits = 44,100 × 16 × 2 × 60
             = 44,100 × 16 = 705,600
             = 705,600 × 2 = 1,411,200
             = 1,411,200 × 60 = 84,672,000 bits

Size in bytes = 84,672,000 ÷ 8 = 10,584,000 bytes
Size in KiB = 10,584,000 ÷ 1024 = 10,335.94 KiB
Size in MiB = 10,335.94 ÷ 1024 = 10.09 MiB

Example 2: 3-minute mono recording at 22,050 Hz, 8-bit

Duration = 3 × 60 = 180 seconds
Size in bits = 22,050 × 8 × 1 × 180
             = 22,050 × 8 = 176,400
             = 176,400 × 180 = 31,752,000 bits

Size in bytes = 31,752,000 ÷ 8 = 3,969,000 bytes
Size in KiB = 3,969,000 ÷ 1024 = 3,876.95 KiB
Size in MiB = 3,876.95 ÷ 1024 = 3.79 MiB

Factors Affecting File Size

Images:

  • Higher resolution → larger file
  • Higher colour depth → larger file
  • Compression → smaller file

Sound:

  • Higher sample rate → larger file
  • Higher sample resolution → larger file
  • More channels (stereo vs mono) → larger file
  • Longer duration → larger file

13. Data Compression

What is Compression?

Compression is the process of reducing the number of bits needed to store or transmit data.

Why Do We Need Compression?

  1. Save storage space – Store more files on devices
  2. Reduce transfer time – Files upload/download faster
  3. Less bandwidth required – Important for streaming and websites
  4. Optimize performance – Applications run smoother

Two Main Types of Compression

TypeData LossUse Cases
LosslessNoneText, code, PNG images
LossySome data discardedPhotos, music, video

Lossless Compression

Characteristics:

  • Original data can be perfectly reconstructed
  • No data is permanently removed
  • Smaller reduction in file size (typically 2:1 to 3:1)

Common Techniques:

1. Run-Length Encoding (RLE)
Replaces repeated characters with a count and the character.

Example:

Original:   AAAABBBCCCCDD
Compressed: 4A3B4C2D

2. Huffman Coding

  • Frequently used characters get shorter binary codes
  • Rarely used characters get longer binary codes
  • Variable-length coding

File Formats using Lossless Compression:

  • PNG (images)
  • GIF (images)
  • FLAC (audio)
  • ZIP (archives)

Lossy Compression

Characteristics:

  • Original data cannot be perfectly reconstructed
  • Some data is permanently removed
  • Much larger reduction in file size (10:1 or more)
  • Acceptable when perfect accuracy isn’t needed

Common Techniques:

For Images (JPEG):

  • Removes fine details the human eye can’t easily see
  • Reduces colour accuracy in some areas
  • Blends similar colours together

For Audio (MP3):

  • Removes frequencies humans can’t hear well
  • Simplifies complex sound patterns
  • Reduces stereo separation

For Video (MP4):

  • Drops unnecessary frames
  • Compresses static backgrounds
  • Reduces colour information

File Formats using Lossy Compression:

  • JPEG (images)
  • MP3 (audio)
  • MP4, AVI (video)

Comparison: Lossy vs Lossless

FeatureLosslessLossy
Data recoveryPerfectApproximate
File size reductionModerateSignificant
ReversibleYesNo
Best forText, code, diagramsPhotos, music, video
ExamplesPNG, FLAC, ZIPJPEG, MP3, MP4

Compression Summary

Original File (10 MB)
        ↓
  [Compression]
        ↓
Lossless (5 MB)     Lossy (2 MB)
   ↓                    ↓
Perfect restore    Approximate restore
   ↓                    ↓
  Text, code         Photos, music

14. Summary & Key Takeaways

Number Systems

SystemBasePurpose
Binary2Computer processing
Denary10Human everyday use
Hexadecimal16Programmer shorthand

Binary Operations

  • Addition: Follow binary addition rules; overflow when result > 255 (8-bit)
  • Left shift: Multiply by 2ⁿ
  • Right shift: Divide by 2ⁿ (integer division)
  • Two’s complement: Represents negative numbers; MSB=0 for positive, MSB=1 for negative

Data Representation

Data TypeRepresentation MethodQuality Factors
TextCharacter sets (ASCII, Unicode)More bits = more characters
SoundSamplingSample rate, sample resolution
ImagesPixelsResolution, colour depth

File Size Formulas

Images: Width × Height × Colour Depth (bits)

Sound: Sample Rate × Sample Resolution × Channels × Duration (seconds)

Storage Units (using 1024)

1 Byte = 8 bits
1 KiB = 1024 bytes
1 MiB = 1024 KiB
1 GiB = 1024 MiB
1 TiB = 1024 GiB

Compression

  • Lossless: No data lost (RLE, Huffman)
  • Lossy: Some data permanently removed (JPEG, MP3)
  • Purpose: Save space, reduce transfer time, less bandwidth

15. Practice Questions

Section A: Number System Conversions

  1. Convert the following binary numbers to denary:
    a) 1011
    b) 110101
    c) 11111111
  2. Convert the following denary numbers to binary (8-bit):
    a) 25
    b) 128
    c) 255
  3. Convert the following hexadecimal to denary:
    a) 1A
    b) FF
    c) 2C
  4. Convert the following denary to hexadecimal:
    a) 30
    b) 100
    c) 255
  5. Convert between binary and hexadecimal:
    a) 10110110 to hex
    b) 3F to binary
    c) A7 to binary

Section B: Binary Addition & Overflow

  1. Add the following 8-bit binary numbers:
    a) 00110101 + 00101010
    b) 01101100 + 00110101
    c) 11001010 + 10110101
  2. Identify which of the additions above cause overflow. Explain why.

Section C: Binary Shifts

  1. Perform a logical left shift by 2 on 00001101. What is the result in denary?
  2. Perform a logical right shift by 3 on 00110010. What is the result in denary?
  3. A binary number 10110011 is left shifted by 1. Which bits are lost and what is the effect on the value?

Section D: Two’s Complement

  1. Convert the following to two’s complement 8-bit:
    a) +25
    b) -25
    c) -128
  2. What denary values do these two’s complement numbers represent?
    a) 11110000
    b) 00001111
    c) 10000000

Section E: Text, Sound & Images

  1. Explain the difference between ASCII and Unicode. Give an advantage of each.
  2. A sound file has a sample rate of 44.1 kHz and 16-bit resolution. Calculate the file size for a 3-minute stereo recording.
  3. An image is 1280 × 720 pixels with 24-bit colour depth. Calculate its file size in MiB.
  4. Explain how increasing the sample rate affects:
    a) Sound quality
    b) File size

Section F: Data Storage & Compression

  1. Convert:
    a) 5 MiB to KiB
    b) 2048 KiB to MiB
    c) 2 GiB to bytes
  2. Explain the difference between lossy and lossless compression. Give an example of when each would be used.
  3. Use Run-Length Encoding to compress: AAABBBBBCCCCCDD
  4. Explain why hexadecimal is used in computer science instead of binary.

Answers to selected questions:

1a) 11
1b) 53
1c) 255

2a) 00011001
2b) 10000000
2c) 11111111

3a) 26
3b) 255
3c) 44

4a) 1E
4b) 64
4c) FF

5a) D6
5b) 00111111
5c) 10100111

6c) 11001010 + 10110101 = 1 01111111 → overflow!

8) 00110100 (52)

9) 00000110 (6)

14) 44,100 × 16 × 2 × 180 = 254,016,000 bits = 31,752,000 bytes = 31,008 KiB = 30.28 MiB

15) 1280 × 720 × 24 = 22,118,400 bits = 2,764,800 bytes = 2,700 KiB = 2.64 MiB

17a) 5 × 1024 = 5120 KiB
17b) 2048 ÷ 1024 = 2 MiB
17c) 2 × 1024 × 1024 × 1024 = 2,147,483,648 bytes


Scroll to Top