Mission 1 · Spec 1.4.1
Negative numbers and binary arithmetic
Primitive data types, sign and magnitude, two's complement, and binary addition and subtraction.
- Starter 5 min
- Learn 15 min
- Lab 20 min
- Quiz 10 min
- Exam 15 min
The car odometer
An old 4-digit odometer reads 0000. If you could drive backwards 1 mile, what would it show?
Reveal
9999. The number just "below" zero is the largest pattern. Two's complement works the same way in binary: 1111 1111 is −1.
Key ideas
Primitive data types: integer, real/floating point, character, string, Boolean.
Sign and magnitude
The most significant bit is the sign (1 = negative); the rest is the size. 1000 0101 = −5. Range −127 to +127, with two zeros; arithmetic is awkward.
Two's complement
The most significant bit has a negative place value (−128 in 8 bits). Range −128 to +127, one zero. To negate: flip all the bits and add 1.
Subtraction
A − B is calculated as A + (−B), using the two's complement of B. Any carry out of the most significant bit is discarded.
Overflow
If the true result is outside the representable range, the answer is wrong, e.g. adding two positives gives a negative.
Two's complement explorer
The first bit is worth −128.Subtraction by addition
Exam-style questions
1. Show how −37 is represented in 8-bit two's complement.
[2 marks]Mark scheme
- 37 =
0010 0101; flip and add 1 (1) 1101 1011(1)
2. Using 8-bit two's complement, calculate 23 − 45. Show your working.
[3 marks]Mark scheme
- 23 =
0001 0111; −45 =1101 0011(1) - Adding them (1)
1110 1010= −22 (1)
TUTOR NOTES
- Check: 45 = 0010 1101 → flip 1101 0010 → +1 = 1101 0011. Sum 0001 0111 + 1101 0011 = 1110 1010 = −128 + 64 + 32 + 8 + 2 = −22.
- Misconception: sign and magnitude and two's complement give the same pattern for negatives.
Mission 2 · Spec 1.4.1
Floating point, masks and character sets
Normalised floating point representation, floating point addition and subtraction, bitwise shifts and masks, and ASCII and Unicode.
- Starter 5 min
- Learn 15 min
- Lab 20 min
- Quiz 10 min
- Exam 15 min
Scientific notation
6.02 × 1023 and 0.0000000000016 fit easily in scientific notation. How could a computer store very large and very small numbers in a fixed number of bits?
Reveal
Store a mantissa (the significant digits) and an exponent (how far to move the binary point). That's floating point: the same idea as scientific notation, in binary.
Key ideas
Floating point
value = mantissa × 2exponent. Both are usually two's complement; the binary point sits after the first bit of the mantissa.
Normalisation
A normalised mantissa starts 01 (positive) or 10 (negative). This gives maximum precision for the number of bits and a unique representation for each number. To normalise, shift the mantissa and adjust the exponent.
Adding floating point numbers
Make the exponents equal (shift the smaller number's mantissa), add the mantissas, then normalise the result.
Masks
AND clears or tests bits; OR sets bits; XOR toggles bits. Logical shifts multiply or divide by 2.
Character sets
ASCII: 7 bits (128 characters), later extended to 8. Unicode: up to 32 bits, representing characters from all languages plus emoji; the first 128 codes match ASCII.
Floating point builder
Masks and shifts
Exam-style questions
1. A floating point number has an 8-bit two's complement mantissa 0101 1000 and a 4-bit two's complement exponent 0011. Calculate its denary value.
Mark scheme
- Mantissa = 0.1011 = 0.6875 and exponent = 3 (1)
- 0.6875 × 23 = 5.5 (1)
2. Explain why floating point numbers are normalised.
[2 marks]Mark scheme
- To give the maximum precision possible with the number of bits in the mantissa (1)
- So each number has a unique representation (1)
3. A byte stores 8 on/off settings. Give the mask and operation to switch on bit 0 (the rightmost) without changing the others.
[2 marks]Mark scheme
- Mask
0000 0001(1) - OR (1)
TUTOR NOTES
- Check: 0.1011 = ½ + ⅛ + 1/16 = 0.6875; × 8 = 5.5.
- Misconception: normalising changes the value. It changes only the representation.
Mission 3 · Spec 1.4.2
Linear data structures
Arrays, records, tuples and lists; stacks, queues and linked lists: how they work and how items are added and removed.
- Starter 5 min
- Learn 15 min
- Lab 25 min
- Quiz 10 min
- Exam 15 min
Undo
You type A, B, C, then press Undo twice. What's left? What data structure would a program use to track your actions?
Reveal
A: the last action is undone first. That's a stack (last in, first out). A printer queue is the opposite: first in, first out.
Key ideas
Arrays, records, lists, tuples
Array: fixed size, one data type, indexed (1D, 2D or 3D). Record: named fields of different types. List: dynamic, can hold mixed types. Tuple: ordered and immutable (can't be changed once created).
Static vs dynamic
A static structure has a fixed size set in advance. A dynamic structure can grow and shrink at run time, using memory from the heap.
Stack
LIFO. Operations: push, pop, peek, isEmpty, isFull. A top pointer tracks the last item. Used for undo, call stacks, backtracking.
Queue
FIFO. Operations: enqueue, dequeue, isEmpty, isFull. Front and rear pointers. A circular queue reuses space: rear = (rear + 1) MOD size.
Linked list
Each node holds data and a pointer to the next node. A start pointer marks the first node, and a free list tracks spare nodes. Items can be inserted and deleted by changing pointers, without moving data.
Stack
Queue
Linked list
Exam-style questions
1. Describe how an item is removed from a circular queue implemented using an array.
[3 marks]Mark scheme
- Check the queue is not empty (1)
- Return / remove the item at the front pointer (1)
- Increment the front pointer, wrapping round: front = (front + 1) MOD size (1)
2. Explain how a new item is inserted into an ordered linked list.
[4 marks]Mark scheme
- Store the item in the node at the free pointer and update the free pointer (1)
- Traverse from the start pointer to find where it belongs (1)
- Set the new node's pointer to the next node (1)
- Set the previous node's pointer (or the start pointer) to the new node (1)
TUTOR NOTES
- Exam habit: always check for empty/full before removing/adding.
- Practical: implement a stack class with push and pop in the student's language.
Mission 4 · Spec 1.4.2
Trees, graphs and hash tables
Binary search trees and their traversals, graphs and their representation, and hash tables with collision handling.
- Starter 5 min
- Learn 15 min
- Lab 25 min
- Quiz 10 min
- Exam 15 min
20 questions
In "20 questions", each yes/no answer rules out half the possibilities. How many objects could you distinguish in 20 questions?
Reveal
220, about a million. A balanced binary search tree works the same way: each comparison halves the remaining items.
Key ideas
Trees
A connected graph with no cycles, with a root and nodes connected by branches. In a binary search tree each node has up to two children; left subtree values are smaller, right are larger.
Traversals
Pre-order: node, left, right. In-order: left, node, right (gives sorted order). Post-order: left, right, node.
Graphs
Nodes (vertices) joined by edges (arcs), which may be directed and/or weighted. Stored as an adjacency matrix (fast to check an edge; wastes space if sparse) or an adjacency list (space-efficient for sparse graphs).
Hash tables
A hash function turns a key into an index, so items can be found in (ideally) one step. Collisions (two keys, same index) are handled by, e.g., linear probing or chaining.
Binary search tree
Hash table
Graph traversal
Exam-style questions
1. The values 40, 25, 60, 10, 30, 50 are added in that order to an empty binary search tree. Give the post-order traversal.
[2 marks]Mark scheme
- 10, 30, 25, 50, 60, 40 (2); 1 mark for one error
2. Compare an adjacency matrix and an adjacency list for storing a graph.
[4 marks]Mark scheme
- A matrix stores every possible edge; a list stores only existing edges (1)
- A list uses less memory for sparse graphs (1)
- A matrix gives fast (constant-time) checks for whether an edge exists (1)
- A list must be searched to find an edge; a matrix is easier to add/remove edges in (1)
TUTOR NOTES
- Check: tree: 40 root; 25 left (10, 30); 60 right (50 left). Post-order: 10, 30, 25, 50, 60, 40.
- Lab prompt: remove a node with two children from the BST and explain the replacement.
Mission 5 · Spec 1.4.3
Boolean algebra
Simplifying expressions with Boolean algebra and De Morgan's laws, Karnaugh maps, adders and D-type flip-flops.
- Starter 5 min
- Learn 15 min
- Lab 25 min
- Quiz 10 min
- Exam 15 min
Two ways to say no
"It is not true that it's cold and raining." Say the same thing without the word "and".
Reveal
"It's not cold, or it's not raining." That's De Morgan's law: ¬(A ∧ B) ≡ ¬A ∨ ¬B.
Key ideas
De Morgan's laws
¬(A ∧ B) ≡ ¬A ∨ ¬B
¬(A ∨ B) ≡ ¬A ∧ ¬B
"Break the bar, change the sign."
Rules
Distribution: A ∧ (B ∨ C) ≡ (A ∧ B) ∨ (A ∧ C)
Association: (A ∨ B) ∨ C ≡ A ∨ (B ∨ C)
Commutation: A ∧ B ≡ B ∧ A
Double negation: ¬¬A ≡ A
Absorption: A ∨ (A ∧ B) ≡ A
Karnaugh maps
Cells arranged in Gray code order, so neighbours differ by one variable. Group 1s in rectangles of 1, 2, 4 or 8 (can wrap around edges). Each group gives one simplified term.
Adders and flip-flops
Half adder: S = A ⊕ B, C = A ∧ B. Full adder adds a carry in; full adders chained together add binary numbers. A D-type flip-flop stores one bit, updating only on the rising edge of the clock.
Karnaugh map
Equivalence checker
Half and full adders
D-type flip-flop
Exam-style questions
1. Simplify ¬(¬A ∨ B) ∨ B.
[3 marks]Mark scheme
- De Morgan: (A ∧ ¬B) ∨ B (1)
- Distribution: (A ∨ B) ∧ (¬B ∨ B) (1)
- ¬B ∨ B = 1, so A ∨ B (1)
2. Draw the circuit for a half adder and explain why a full adder is needed to add multi-bit numbers.
[4 marks]Mark scheme
- XOR gate with inputs A and B giving S (1)
- AND gate with inputs A and B giving C (1)
- A half adder has no carry input (1)
- A full adder adds the carry from the previous column, so full adders can be chained (1)
TUTOR NOTES
- Check Q1 in the equivalence checker: type
¬(¬A ∨ B) ∨ BandA ∨ B. - K-map habit: make groups as large as possible; overlapping is allowed.