A Level · Chapter 13

Data Representation

User-defined types · File organisation · Floating-point numbers


🧩 13.1 User-Defined Data Types
Core Idea
Built-in types (INTEGER, STRING…) aren’t always enough. When modelling real-world things, you define your own types — making code clearer, safer, and more self-documenting.
Non-Composite Types

These store a single value, but of a custom kind.

🏷️ Enumerated Type

A fixed list of named values. The compiler assigns integer codes internally.

TYPE Season = (Spring, Summer, Autumn, Winter) DECLARE today : Season today ← Summer
Why use it
Prevents magic numbers. today = 1 is cryptic; today = Summer is readable.

👉 Pointer Type

Stores a memory address rather than a value. Essential for dynamic data structures like linked lists and trees.

TYPE IntPointer = ^INTEGER DECLARE p : IntPointer p ← ^myVar // p holds address // of myVar
Analogy
A pointer is like a Post-It note with a house address written on it — not the house itself, just directions to find it.
Composite Types

These bundle multiple fields or values together.

A record groups related data of different types under one name — like a database row.

TYPE Student DECLARE name : STRING DECLARE age : INTEGER DECLARE grade : REAL ENDTYPE DECLARE s : Student s.name ← “Aisha” s.age ← 17 s.grade ← 91.5
Real world
A school database stores name, DOB, scores together — that’s a record.

A set holds distinct values with no duplicates and no defined order. Supports mathematical set operations.

TYPE LetterSet = SET OF CHAR DECLARE vowels : LetterSet vowels ← {‘a’,’e’,’i’,’o’,’u’} // Operations: // Union: A ∪ B // Intersection: A ∩ B // Difference: A – B

Useful when you need membership testing: Is ‘e’ in vowels?

A class is a blueprint combining data (attributes) and behaviour (methods). An object is an instance of a class.

CLASS BankAccount PRIVATE balance : REAL PUBLIC PROCEDURE deposit(amount : REAL) balance ← balance + amount ENDPROCEDURE PUBLIC FUNCTION getBalance() RETURNS REAL RETURN balance ENDFUNCTION ENDCLASS DECLARE acc : BankAccount acc.deposit(500) OUTPUT acc.getBalance() // 500
Key OOP terms
Encapsulation Inheritance Polymorphism Aggregation Getter / Setter

🗄️ 13.2 File Organisation & Access

How records are physically arranged on disk determines how quickly they can be found.

MethodHow records are storedAccess typeBest for
SerialIn order of arrival — no sortingSequential onlyLog files, backups
SequentialSorted by a key fieldSequential or DirectBatch processing, sorted reports
RandomAddress computed via hash of keyDirect (fast!)Real-time lookups, e.g. bank accounts
Analogy
Serial = pile of unsorted papers. Sequential = alphabetical filing cabinet. Random = indexed database where you jump straight to the right drawer.
Hashing Algorithms

Random files use a hashing function to convert a record key into a storage address.

Address = Key MOD NumberOfSlots Example: Key = 1047, Slots = 100 Address = 1047 MOD 100 = 47 → Store/retrieve record at slot 47

A collision occurs when two different keys hash to the same address.

Solutions:

  • Linear probing: Try next slot (Address+1, Address+2…) until empty slot found
  • Chaining: Each slot holds a linked list of records that hash there
  • Double hashing: Apply a second hash function to find the next probe position
Exam tip
You may be asked to trace through a hash function with linear probing — show each step explicitly.

🔢 13.3 Floating-Point Numbers

Integers can’t represent fractions. Floating-point sacrifices exactness for range by splitting the bits into two parts:

S
1 bit
MANTISSA (significand)
The actual digits / precision
EXPONENT
Scale / magnitude
Value = Mantissa × 2^Exponent
Analogy
Scientific notation: 3.14 × 10² = 314. Mantissa = 3.14, Exponent = 2. Floating-point is exactly this, but in binary.
Two’s Complement in Floating Point

Both mantissa and exponent are stored in two’s complement form.

8-bit format: 5-bit mantissa, 3-bit exponent (both two’s complement)

Binary: 0 1 1 0 1 | 0 1 0 mantissa | exponent Step 1 – Exponent: 010 in two’s complement = +2 Step 2 – Mantissa: 01101 = +0.1101 (normalised, leading .0 or .1) Value = 0.1101₂ Step 3 – Apply exponent (shift point right 2): 0.1101 × 2² = 011.01₂ Step 4 – Convert: 011.01₂ = 3.25₁₀ ✓
Rule
Positive exponent → shift binary point RIGHT. Negative exponent → shift LEFT.
Normalisation

A number is normalised when the mantissa starts with the most significant bit — no leading redundant zeros or ones.

✅ Normalised

Positive: 0.1xxxxxxx (first bit after point = 1) Negative: 1.0xxxxxxx (first bit after point = 0)

❌ Not Normalised

0.0xxxxxxx ← wasted bits! 1.1xxxxxxx ← redundant sign

Leading redundant bits reduce precision — normalisation maximises the meaningful bits in the mantissa.

Mantissa vs Exponent Bits Trade-off
More bits to…Effect on precisionEffect on range
Mantissa✅ Higher precision (more decimal places)❌ Smaller range
Exponent❌ Lower precision✅ Larger range (bigger/smaller numbers)

📈 Overflow

Number too large for the exponent bits to represent. Result wraps or becomes infinity.

📉 Underflow

Number too small/close to zero for the exponent. Result rounds to 0 incorrectly.

Rounding errors
Most real numbers can’t be represented exactly in binary. For example, 0.1 in decimal is a repeating fraction in binary (0.0001100110011…). Every time arithmetic is done, tiny errors accumulate. This is why 0.1 + 0.2 ≠ 0.3 in many programming languages!
⚡ Exam Essentials
  • Know how to convert binary float → denary and back
  • Normalise a given floating-point number
  • Explain why binary representations are approximations
  • Describe consequences of changing mantissa vs exponent allocation

📓 Other Notes:

Chapter 14: Communication & Internet Chapter 15: Hardware & Virtual Machines Chapter 16: System Software Chapter 17: Security Chapter 18: Artificial Intelligence

📋 9618/4 Detailed Exam Guide →

Stop wrestling with confusion.

Join thousands of students mastering Computer Science without the academic jargon.

From syntax to systems. We break down the hardest ideas in computer science so you can actually build things.

© 2026 Painless Programming. Built for students.
Scroll to Top