COMPUTING
Comprehensive Study Notes
Cambridge IGCSE & O Level Computer Science
Based on: Cambridge IGCSE & O Level Computer Science Coursebook (Lawrey & Ellis)
PART 1 — 20 MARKS: Short-answer and structured
questions
CHAPTER 1: DATA REPRESENTATION
1.1 Binary and Hexadecimal
Why Do Computers Use Binary?
Humans process what is called analogue data — a continuous stream of information that we see, hear, feel
and smell. Computers are different. The components inside a computer that process data are made up of very
small logic gates. These logic gates cannot process analogue data — they can only process digital data.
Digital data is discrete data that has only two values: 1 and 0. All data that a computer processes must be
converted into this binary (digital) form. The binary values 1 and 0 correspond to the two states of electricity:
high voltage = 1, low voltage = 0.
Number Systems
Denary (Base-10): The number system humans use every day. It uses 10 digits: 0 through 9. Each position in
a number represents a power of 10. For example, the number 237 means: 2 hundreds + 3 tens + 7 ones (2 ×
100 + 3 × 10 + 7 × 1).
Binary (Base-2): The number system computers use. It uses only 2 digits: 0 and 1. Each position represents
a power of 2. The positions from right to left are: 1, 2, 4, 8, 16, 32, 64, 128 (for 8-bit numbers). Each time you
move one position to the left, the value doubles.
Hexadecimal (Base-16): Uses 16 symbols: digits 0–9 and letters A–F. A=10, B=11, C=12, D=13, E=14,
F=15. This is used by humans (not by computers) because it is a shorter, more readable way to represent
binary. Computers must convert hexadecimal to binary before processing it.
Converting Denary to Binary — Step by Step
For 4-bit binary, the column values (right to left) are: 8, 4, 2, 1.
For 8-bit binary, the column values (right to left) are: 128, 64, 32, 16, 8, 4, 2, 1.
For 16-bit binary, continue doubling left: 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8,
4, 2, 1.
Method:
• Write the column values from left to right.
• Compare your denary number to the leftmost column value.
• If the denary number is greater than or equal to the column value, write a 1 and subtract the column
value from your denary number.
• If the denary number is less than the column value, write a 0 and do not subtract.
• Move to the next column value and repeat until you have filled all columns.
Worked Example 1: Convert denary 13 to 4-bit binary
Column values: 8, 4, 2, 1
13 >= 8? YES → write 1, remainder = 13 - 8 = 5
5 >= 4? YES → write 1, remainder = 5 - 4 = 1
1 >= 2? NO → write 0, remainder stays 1
1 >= 1? YES → write 1, remainder = 1 - 1 = 0
Answer: 1101
Worked Example 2: Convert denary 150 to 8-bit binary
Column values: 128, 64, 32, 16, 8, 4, 2, 1
150 >= 128? YES → 1, remainder = 22
22 >= 64? NO → 0
22 >= 32? NO → 0
22 >= 16? YES → 1, remainder = 6
6 >= 8? NO → 0
6 >= 4? YES → 1, remainder = 2
2 >= 2? YES → 1, remainder = 0
0 >= 1? NO → 0
Answer: 10010110
Quick check: if the denary number is odd, the rightmost binary digit must be 1. If even, it must be 0.
Converting Binary to Denary:
Write the column values above each binary digit. Add together only the column values that have a 1 beneath
them.
Example: 10011001 → columns with 1s are: 128, 16, 8, 1 → 128 + 16 + 8 + 1 = 153
Hexadecimal — Conversion Methods
Denary to Hexadecimal:
Step 1: Convert the denary number to 8-bit binary first.
Step 2: Split the 8-bit binary number into two groups of 4 bits.
Step 3: Convert each 4-bit group to its hexadecimal digit using the table below.
Worked Example: Convert denary 201 to hexadecimal
Step 1: 201 in binary = 11001001
Step 2: Split → 1100 | 1001
Step 3: 1100 = 8+4 = 12 = C; 1001 = 8+1 = 9
Answer: C9
Hexadecimal to Binary:
Convert each hex digit separately to 4-bit binary, then join them.
Example: 5E → 5 = 0101, E (=14) = 1110 → Binary: 01011110
Hexadecimal to Denary:
Convert the hex to binary first, then use the column value method to get denary.
Example: 5E → 01011110 → 64 + 16 + 8 + 4 + 2 = 94
Denary Binary (4-bit) Hexadecimal
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F
Why Is Hexadecimal Used in Computer Science?
Hexadecimal is used because it provides a much shorter, human-readable way of representing binary data.
For example:
• Binary: 10011100101110111000111011100010111101011010
• Hexadecimal: 9CBB8EE2F5A
The hexadecimal version is much easier for a programmer to read, compare and debug. Specific uses
include:
• Debugging — programmers look at memory addresses in hex to find variable values and locate
errors. For instance, FFFF or 0000 can indicate an uninitialised variable.
• MAC addresses — every network device has a unique MAC (Media Access Control) address written
in hexadecimal.
• Colour codes — RGB colours on computers are written in hexadecimal. For example, #FF0000
means full red (FF), no green (00), no blue (00).
• Error codes — operating systems display error codes in hexadecimal.
1.2 Binary Manipulation and Negative Numbers
Binary Addition
You must be able to add two 8-bit binary numbers. There are exactly four rules:
Rule 1: 0 + 0 = 0
Rule 2: 1 + 0 = 1 (or 0 + 1 = 1)
Rule 3: 1 + 1 = 10 → write 0, carry 1 to the next column (because binary 10 = denary 2)
Rule 4: 1 + 1 + 1 = 11 → write 1, carry 1 (because binary 11 = denary 3)
Always start from the rightmost (least significant) bit and work left. Apply the rules column by column, carrying
values where needed.
Worked Example: Add 10010100 and 00011110
Rightmost column: 0 + 0 = 0 (Rule 1)
Next column: 0 + 1 = 1 (Rule 2)
Next column: 1 + 1 = 10 → write 0, carry 1 (Rule 3)
Next column: 0 + 1 + carry1 = 1 + 1 = 10 → write 0, carry 1 (Rule 3)
Next column: 1 + 1 + carry1 = 11 → write 1, carry 1 (Rule 4)
Next column: 0 + 0 + carry1 = 1 (Rule 2)
Next column: 0+0=0
Leftmost column: 1 + 0 = 1
Answer: 10110010
Overflow Error
Overflow error: An error that occurs when the result of a binary addition is too large to be stored in the
available register size. For an 8-bit register, the maximum storable value is 255 (11111111). If two 8-bit
values are added and the result exceeds 255, a 9th bit would be needed — but there is no room for it. The
extra bit is lost and the stored result is incorrect. An overflow error is generated.
Example: If two numbers add up to 306, this requires more than 8 bits. The register can only hold 8 bits, so
the result stored is wrong and an overflow error occurs.
Note: Each computer has a predefined register size (e.g. 16-bit, 32-bit, 64-bit). The maximum storable value in
a 16-bit register is 65,535.
Logical Binary Shifts
A logical binary shift moves all the bits in a binary number either to the left or to the right by a specified
number of places. When bits are shifted out of the register, they are lost. Empty positions created by the shift
are always filled with 0.
Left Shift (× 2 per shift):
Each position shifted left multiplies the binary number by 2.
The leftmost bit drops off (is lost). A 0 fills in on the right.
Example: 00101100 (= 44) → shifted left 1 place → 01011000 (= 88). That is 44 × 2 = 88.
Two shifts left: 44 × 4 = 176. Three shifts left: 44 × 8 = 352.
Right Shift (÷ 2 per shift):
Each position shifted right divides the binary number by 2 (integer division).
The rightmost bit drops off (is lost). A 0 fills in on the left.
Example: 00101100 (= 44) → shifted right 1 place → 00010110 (= 22). That is 44 ÷ 2 = 22.
Important limitation:
If significant bits (1s) are shifted out of the register, the number loses accuracy. For example, 11101100 (236)
shifted left: the leading 1 is lost, giving a result of 11011000 (216), not 472. This means binary shifts can
cause data loss and incorrect results if care is not taken.
Two's Complement — Representing Negative Numbers
Binary only has two symbols (0 and 1) — there is no minus sign. Two's complement is the standard method
used by most modern computers to represent negative binary numbers.
Method (to represent a negative number, e.g. −35):
• Step 1: Convert the positive version of the number to 8-bit binary. 35 = 00100011
• Step 2: Invert (flip) every bit — change all 0s to 1s and all 1s to 0s. → 11011100
• Step 3: Add 1 to the result of step 2. 11011100 + 1 = 11011101
Answer: 11011101 is the 8-bit two's complement representation of −35.
How to recognise a negative number in two's complement: if the most significant bit (leftmost bit) is 1, the
number is negative. If it is 0, the number is positive.
To convert a two's complement number back to denary: apply the same process in reverse (invert all bits, add
1, then convert to denary and make it negative).
1.3 Representation of Text, Images and Sound
Representing Text — Character Sets
Computers can only process binary, so all text characters must be converted to binary using a character set.
A character set is a mapping table that assigns a unique binary code to every character it contains, including
letters, digits, punctuation marks, and special symbols.
ASCII (American Standard Code for Information Interchange): Uses 8-bit binary numbers to represent
characters. With 8 bits there are 2⁸ = 256 possible codes (values 0 to 255). This is enough to represent
the English alphabet (upper and lowercase), digits, and common symbols. However, many languages
have alphabets larger than 256 characters, so ASCII is insufficient for international use.
Unicode: Uses 16-bit binary numbers, allowing 2¹⁶ = 65,536 possible codes (approximately 65,000
characters). This is large enough to represent characters from most of the world's alphabets,
mathematical symbols, currency symbols, and even emoji. Unicode is now the international standard.
Example: In ASCII, the letter 'A' is represented by 01000001 in binary (= denary 65). Lowercase 'a' has a
different binary code to uppercase 'A'.
Representing Images — Pixels and Colour
Pixel: A pixel (picture element) is the smallest individual dot of colour that makes up a digital image. An
image is made up of thousands or millions of pixels arranged in a grid.
In a simple black-and-white image: 1 = black, 0 = white. Each pixel only needs 1 bit.
Colour images require more bits per pixel to represent the range of colours.
Colour depth (bit depth): The number of bits used to represent the colour of each pixel. The greater the
colour depth, the more colours can be represented and the higher the image quality — but the larger the
file size.
Examples of colour depth:
• 1-bit: 2 colours (black and white only)
• 8-bit: 2⁸ = 256 colours
• 16-bit: 2¹⁶ = 65,536 colours
• 24-bit (True Colour): 2²⁴ = 16,777,216 colours — uses 8 bits each for Red, Green, and Blue
RGB Colour System: Screens create colours by mixing three primary colours: Red, Green, and Blue
(RGB). Each channel has a value from 0 (none) to 255 (maximum). For example: pure red = (255, 0, 0);
pure white = (255, 255, 255); black = (0, 0, 0). RGB values are often shown in hexadecimal — e.g.
#FF0000 is pure red.
Resolution: The dimensions of an image measured in pixels — width × height. For example, 1920 ×
1080 means the image is 1920 pixels wide and 1080 pixels tall. A higher resolution means more pixels
and more detail, but also a larger file size.
Metadata: Additional data stored inside an image file that describes the image itself. Examples include:
image dimensions (resolution), colour depth, the date and time the photo was taken, camera settings. The
metadata is not part of the visible image but is needed by programs to correctly display it.
Calculating Image File Size:
Formula: File size (bits) = width (pixels) × height (pixels) × colour depth (bits per pixel) × number of images
To convert to bytes: divide by 8 (1 byte = 8 bits)
To convert bytes to KiB: divide by 1024
To convert KiB to MiB: divide by 1024 again
Worked Example:
An image file contains 10 images. Each image is 100 × 150 pixels with 8-bit colour depth.
Step 1: 100 × 150 = 15,000 pixels per image
Step 2: 15,000 × 8 = 120,000 bits per image
Step 3: 120,000 × 10 = 1,200,000 bits total
Step 4: 1,200,000 ÷ 8 = 150,000 bytes
Step 5: 150,000 ÷ 1024 = 146.5 KiB (to 1 decimal place)
Representing Sound — Sampling
Sound in the real world is a continuous analogue wave (a constantly changing pressure wave). To store
sound digitally, the computer takes measurements (samples) of the sound wave at regular time intervals.
Each sample value is then converted to binary.
Sample rate: The number of samples recorded per second. Measured in Hz or kHz. A higher sample rate
captures the sound wave more accurately (more detail) but results in a larger file. A common sample rate
for music is 44,100 Hz (44.1 kHz) — meaning 44,100 samples are taken every second.
Sample resolution (bit depth): The number of bits used to represent each individual sample value. A
higher sample resolution allows more variations in the amplitude (loudness) of the sound to be recorded,
giving a more accurate recording — but again increasing the file size. A common sample resolution is 16-
bit.
If too few samples are taken (low sample rate), there are gaps between them, and the playback does not
accurately reproduce the original sound.
Calculating Sound File Size:
Formula: File size (bits) = sample rate × sample resolution × duration (seconds)
Worked Example:
A sound file is 30 seconds long, with a sample rate of 44,100 Hz and sample resolution of 8 bits.
Step 1: 44,100 × 8 = 352,800 bits per second
Step 2: 352,800 × 30 = 10,584,000 bits
Step 3: 10,584,000 ÷ 8 = 1,323,000 bytes
Step 4: 1,323,000 ÷ 1024 ÷ 1024 = 1.3 MiB (to 1 decimal place)
1.4 Measuring Data Storage
All data sizes are ultimately measured in bits and bytes, but larger units are used for convenience.
Unit Abbreviation Equivalent
Bit b The smallest unit — a single 0 or 1
Nibble - 4 bits
Byte B 8 bits
Kibibyte KiB 1,024 bytes (2¹⁰)
Mebibyte MiB 1,024 KiB (2²⁰ bytes)
Gibibyte GiB 1,024 MiB (2³⁰ bytes)
Tebibyte TiB 1,024 GiB (2⁴⁰ bytes)
Pebibyte PiB 1,024 TiB
Exbibyte EiB 1,024 PiB
Note: You may also encounter the terms Kilobyte (KB = 1000 bytes), Megabyte (MB), Gigabyte (GB). These
are slightly different from KiB, MiB, GiB — the exact system used in this specification is the binary (IEC) units
above.
1.5 Data Compression
Compression: A method that uses an algorithm to reduce the size of a file. Compressed files take up
less storage space, are faster to transmit over a network, and quicker to upload or download.
Benefits of compressing files:
• Less storage space is needed.
• Files take less time to transmit from one device to another.
• Quicker to upload and download over the internet.
• Less bandwidth (network capacity) is needed.
Lossy Compression
Lossy compression permanently removes data from the file — data that is considered unnecessary or that
humans cannot easily detect. Because data is permanently deleted, the original file cannot be perfectly
recovered after compression.
For image files, lossy compression can reduce size by:
• Reducing the colour depth — removing colours that the human eye cannot distinguish between.
• Reducing the resolution — decreasing the number of pixels, making the image smaller.
For sound files, lossy compression can reduce size by:
• Removing sounds that the human ear cannot hear (e.g. very high frequencies).
• Removing softer sounds that are masked by louder sounds played at the same time — humans only
hear the louder sound anyway. This technique is called perceptual music shaping.
• Reducing the sample rate or sample resolution.
Perceptual music shaping: A technique used in lossy audio compression (e.g. MP3) that removes
sounds outside the range of human hearing or sounds that are masked by other louder sounds, since
humans cannot hear them anyway.
Lossy compression is NOT suitable for text files — even a single changed or missing character could make a
document unreadable or completely change its meaning.
Lossless Compression
Lossless compression reduces the file size without permanently removing any data. The original file can be
perfectly and completely restored by decompressing it. All the original data is preserved.
One method of lossless compression works by identifying repeating patterns of data and storing them more
efficiently. Instead of repeating the same data multiple times, a lookup table can be used.
Text example:
Original message: WHEN IT IS SNOWING HEAVILY LOOK OUTSIDE. LOOK OUTSIDE IT IS SNOWING
HEAVILY.
This contains 62 characters and would need 62 bytes to store.
Using lossless compression, a lookup table stores each unique word and the positions it appears:
Word Position(s) in message
WHEN 1
IT 2, 10
IS 3, 11
SNOWING 4, 12
HEAVILY 5, 13
LOOK 6, 8
OUTSIDE 7, 9
This lookup table requires only 46 bytes — a 26% saving. No data is lost. To reconstruct the message, the
computer reads the words and places them at their listed positions.
Run-Length Encoding (RLE): A lossless compression algorithm used on image files. Instead of storing
the colour value of every single pixel individually, it groups consecutive (repeating) pixels of the same
colour together and stores the count followed by the colour. For example, a row of 12 white pixels
followed by 4 black pixels would be stored as: 12W, 4B — just 4 values instead of 16.
Example: A row of pixels in an image might be encoded as: 2W, 3Y, 5W, 2Y, 1R — meaning 2 white, 3 yellow,
5 white, 2 yellow, 1 red. The resolution of the image is stored separately so the image can be recreated at the
correct dimensions.
CHAPTER 3: HARDWARE
3.1 The CPU and Fetch-Decode-Execute Cycle
CPU (Central Processing Unit): The component in a computer that processes all data and instructions.
It is often described as the 'brain' of the computer. All computers have a CPU — in a PC or laptop it is a
separate chip; in embedded systems such as washing machines or traffic lights, a similar component
called a microprocessor performs the same role.
Von Neumann Architecture: The design used by most modern computers, in which both data and
program instructions are stored in the same memory (RAM). A CPU follows this architecture.
Fetch-Decode-Execute Cycle (FDE Cycle): The repeating sequence of steps the CPU uses to process
every instruction. 1. Fetch: Get the next instruction from RAM into the CPU. 2. Decode: Interpret the
instruction to determine what action is needed. 3. Execute: Carry out the required action.
CPU Registers and Components
Registers are small, fast storage locations built directly into the CPU. They are used to temporarily hold data
and instructions being processed.
Component Abbrevi Role
ation
Program Counter PC Stores the memory address (location in RAM) of the next
instruction to be fetched. After each fetch, the PC is
automatically incremented to point to the following
instruction.
Memory Address Register MAR Holds the memory address of the data or instruction that is
about to be fetched from (or written to) RAM.
Memory Data Register MDR Temporarily holds the data or instruction that has just been
fetched from RAM, before it is sent on.
Current Instruction CIR Part of the Control Unit. Holds the instruction currently being
Register decoded and executed.
Control Unit CU Controls the entire operation of the CPU. Decodes
instructions using the instruction set. Sends control signals
to all other components to coordinate their activity.
Arithmetic Logic Unit ALU Performs all arithmetic calculations (add, subtract, etc.) and
logical comparisons (AND, OR, NOT, comparisons like > or
<).
Accumulator ACC A special register inside the ALU. Stores interim (temporary)
results during calculations.
The Three Stages of the FDE Cycle in Detail
Stage 1 — FETCH:
• The PC contains the address of the next instruction to process.
• This address is copied from the PC to the MAR via the address bus.
• The MAR sends the address to RAM along the address bus.
• RAM sends back the instruction stored at that address to the MDR via the data bus.
• The MDR sends the instruction to the CIR via the data bus.
• The PC is incremented (increased by 1) to point to the next instruction.
Stage 2 — DECODE:
• The CU receives the instruction from the CIR.
• The CU uses the instruction set (a set of all commands the CPU understands, in machine code) to
decode the instruction — working out what action is needed.
Stage 3 — EXECUTE:
• The required actions are carried out.
• If calculations are needed, the relevant data is sent to the ALU.
• The ALU uses the accumulator to store interim results.
• Results may be written back to RAM or stored in registers.
The Three Buses
Address Bus: Carries memory addresses from the CPU to RAM (and other components). Uni-directional
— travels in one direction only (CPU → RAM).
Data Bus: Carries data and instructions between the CPU, RAM, and other components. Bi-directional —
can travel in both directions.
Control Bus: Carries control signals from the Control Unit to all other components, coordinating the
operations of the whole computer. Also bi-directional.
Factors Affecting CPU Performance
1. Number of Cores:
A core is the part of the CPU that contains all the components needed to perform one fetch-decode-execute
cycle. A CPU with one core can process one instruction at a time. A dual-core CPU has two cores and can
perform two fetch-decode-execute cycles simultaneously. A quad-core CPU has four cores and can process
four cycles at once.
More cores = better performance for multitasking and parallel tasks. A 2.4 GHz dual-core processor can
process 2 × 2.4 billion = 4.8 billion instructions per second.
Note: Adding more cores does not always improve performance proportionally, because not all tasks can be
split across multiple cores effectively.
2. Clock Speed:
Every CPU has an internal clock that controls the rate at which instructions are processed. Clock speed is
measured in Hertz (Hz). 1 Hz = 1 cycle per second.
Modern computers have clock speeds measured in GHz (gigahertz). A 1 GHz CPU executes 1 billion fetch-
decode-execute cycles per second. A 3.5 GHz CPU executes 3.5 billion per second.
A higher clock speed means more instructions processed per second, leading to better performance. Clock
speed can be artificially increased beyond the manufacturer's specification — this is called overclocking — but
it generates more heat and may cause instability.
3. Cache Size:
The cache is a small, very fast memory built directly into the CPU. It stores copies of the most frequently
accessed data and instructions. When the CPU needs a piece of data, it checks the cache first. If the data is
found there (called a cache hit), the CPU can retrieve it very quickly without having to go to RAM. If the data is
not in the cache (a cache miss), it must be fetched from the slower RAM.
A larger cache means more frequently used data can be stored, reducing the number of slow RAM accesses
and improving performance. However, if the cache is too large, the CPU takes longer to search through it —
this can actually slow performance. Cache is much faster than RAM but significantly more expensive per byte.
3.2 Input and Output Devices
Input Devices
An input device is any device that allows data to be entered into a computer system. The data can take many
forms — text, images, audio, movement, etc.
Input Device Description / Data Entered Example Use
Keyboard Detects key presses. Each key is Typing documents, entering
mapped to a character code. Sends text, passwords, data entry
numbers and command characters to
the computer.
Optical Mouse Detects movement using a light source Navigating a graphical interface
and sensor. Sends X/Y coordinate data
and click events.
Barcode Scanner Emits a laser beam that reflects off a Supermarket checkouts, stock
barcode. The pattern of bars is decoded control, parcel tracking
into a product number.
QR Code Scanner Reads the pattern of squares in a QR Mobile payments, marketing,
code and decodes the information ticketing
stored, often a URL.
Digital Camera Captures light through a lens onto a Photography, video calls,
sensor. Converts light intensity to digital security cameras
image data.
Microphone Converts sound waves (pressure Voice recording, speech
variations in air) into electrical signals, recognition, video calls
then digital data.
2D/3D Scanner A 2D scanner converts a flat physical Digitising documents, medical
document to a digital image. A 3D imaging, 3D printing
scanner builds a 3D digital model of a
physical object.
Touch Screen (resistive) Two conductive layers — pressing Older phones, ATMs, industrial
deforms them to make contact at a machines
point. Detects location of touch.
Touch Screen Uses the electrical charge of the human Modern smartphones, tablets
(capacitive) finger. Does not require pressure. Multi-
touch capable.
Touch Screen (infrared) A grid of infrared beams crossing the Large interactive displays,
screen. A touch interrupts the beams — kiosks
position is detected.
Output Devices
An output device is any device that presents the result of processed data to the user or environment.
Output Device Description / Data Output Example Use
LCD Screen Liquid Crystal Display — uses liquid Computer monitors, TV screens,
crystals with a backlight to produce laptop displays
images.
LED Screen Uses individual light-emitting diodes Modern TVs, large outdoor displays
— brighter and more energy-efficient
than LCD.
LCD/DLP Projector Projects an enlarged image onto a Presentations, cinemas,
surface. DLP uses tiny mirrors on a classrooms
chip.
Inkjet Printer Sprays tiny droplets of ink onto Home and office printing,
paper to form text and images. photographs
Laser Printer Uses a laser to create an Office environments, high-volume
electrostatic image on a drum; toner printing
powder is attracted to it and fused to
paper by heat. Faster and sharper
than inkjet.
3D Printer Builds a physical 3D object layer by Prototyping, manufacturing,
layer from a digital design file. medical implants
Speaker Converts electrical signals back into Music, alerts, voice output
sound waves using an
electromagnet and vibrating cone.
Actuator A motor or mechanical device that Automated systems — moving
converts an electrical signal into robotic arms, opening valves,
physical movement or action. triggering mechanisms
Sensors
Sensor: A special type of input device used in automated systems. Sensors capture analogue data from
the surrounding environment and convert it into digital data for the computer to process. They are usually
set to take readings at regular time intervals — sometimes every second, or even multiple times per
second.
Automated system: A computer system designed to operate without human intervention. It continuously
monitors conditions using sensors and responds automatically based on the data.
Sensor What It Measures Example Use
Temperature Heat levels in the surrounding Central heating systems, greenhouses,
environment industrial ovens, fridge controllers
Light Intensity of light in the Street lights that automatically turn on at dusk,
environment automatic blinds
Pressure Force being applied to the Security systems (opening doors/windows
sensor reduces pressure), industrial pipe monitoring
Magnetic field Presence and strength of Counting cars in a car park (a car disrupts
magnetic fields Earth's magnetic field as it passes)
Humidity Amount of water vapour in the Smart farming systems to ensure optimal soil
air or moisture in soil conditions for crops
Infrared Body heat or movement Burglar alarm motion detectors, automatic
hand dryers
pH Acidity or alkalinity of a liquid Monitoring water quality in rivers/lakes,
swimming pools
Gas Concentration of specific gases Carbon monoxide detectors in homes,
in the atmosphere monitoring factories for toxic gases
Accelerometer Movement, vibration, and force Airbag deployment in cars (detects a crash),
(dynamic and static) protecting laptop hard drives from drops
Flow Rate at which liquid, gas or Nuclear power plants, oil refineries — ensuring
steam flows through a pipe safe flow rates
Moisture Water content in a substance or Agricultural irrigation systems
soil
3.3 Data Storage
Primary Storage
Primary storage is directly accessible by the CPU. It is very fast but typically smaller in capacity than
secondary storage.
RAM (Random Access Memory): Volatile (temporary) memory. Holds the programs and data currently
being used by the CPU. Data in RAM is lost when power is switched off. Both reading and writing are
possible. The OS loads programs from secondary storage into RAM so the CPU can access them quickly.
ROM (Read-Only Memory): Non-volatile (permanent) memory. Stores the firmware — the instructions
that run when the computer is first switched on (the bootstrap process). Cannot normally be written to or
changed. Data in ROM is retained without power.
Cache: Very fast memory built directly into the CPU chip. Stores copies of frequently used instructions
and data. Much faster than RAM but more expensive per byte and smaller in capacity.
Secondary Storage
Secondary storage is non-volatile — it retains data even when the computer is switched off. It is not directly
accessed by the CPU; data must be loaded into RAM first. Secondary storage has much larger capacity than
primary storage but is slower to access.
Type How It Works Examples Advantages Disadvantages
Magnetic Circular platters (disks) spin at Hard Disk Very large storage Has many moving
high speed. A read/write head Drive (HDD) capacity; relatively parts — susceptible to
moves across the platter cheap per gigabyte; can physical damage if
surface. An electromagnet store data for many dropped or knocked.
magnetises tiny dots on the years. Slower than SSD.
platter. A magnetised dot = Mechanical parts wear
binary 1; demagnetised = over time.
binary 0. Billions of these dots
are organised into tracks and
sectors.
Optical A laser beam is shone onto a CD, DVD, Blu- Cheap to manufacture; Lower capacity than
spinning circular disc. A write ray Disc portable and easy to HDD/SSD; slower to
laser burns tiny pits into the distribute; can be read- read/write; easily
disc surface; areas between only (ROM), recordable scratched; can
pits are called lands. When (R) or rewritable (RW). degrade over time;
reading, a read laser reflects becoming less popular.
differently off pits and lands —
the pattern encodes binary
data. Pits and lands are
arranged in a spiral track from
the disc centre.
Solid-State No moving parts. Uses SSD (Solid No moving parts — very More expensive per
semiconductor chips made of State Drive), durable and resistant to gigabyte than HDD;
transistors arranged in a grid. USB flash physical damage; fast cells wear out after
NAND gate technology is used. drive, SD card read/write speeds; many write cycles;
Each transistor can store a silent; compact and data recovery can be
charge representing 0 or 1. lightweight. more difficult after
When the device is failure.
manufactured all cells are set to
1. Writing data stores a charge,
converting the cell to 0.
Cloud Storage: Storing data on remote servers accessed via the internet, rather than on local hardware.
Providers like Google Drive and OneDrive manage the servers. Benefits: accessible from any device with
internet; no risk of local physical damage; easy sharing. Drawbacks: requires internet connection; privacy
and security concerns; ongoing subscription cost.
CHAPTER 4: SOFTWARE
4.1 Types of Software
Software: A collection of instructions written in a programming language that tells the computer what to
do. Software is the non-physical part of a computer system.
System Software
System software manages the hardware and other software on the computer. It allows communication
between hardware components and application software.
• Operating System (OS) — manages all hardware/software and provides the user interface.
• Utility Programs — maintenance software (e.g. disk cleanup, defragmentation, antivirus, backup).
• Device Drivers — translate data between the OS and peripheral hardware.
Application Software
Application software provides services to the user, allowing them to complete specific tasks.
Generic Name Purpose Brand Examples
Word Processor Creates, edits and formats text- Microsoft Word, Google Docs
based documents.
Spreadsheet Performs calculations and analysis Microsoft Excel, Google Sheets
on data arranged in rows and
columns.
Database Software Stores, organises, queries and Microsoft Access
manipulates structured data.
Web Browser Requests, retrieves and displays Google Chrome, Mozilla Firefox,
web pages from the internet. Safari
Presentation Software Creates slideshows with text, images Microsoft PowerPoint, Google
and animations. Slides
Graphics Software Edits photographs and creates Adobe Photoshop, GIMP
digital artwork.
Boot Process — Software Hierarchy
When a computer is switched on, the following sequence occurs:
• The Bootstrap program is the very first thing that runs when power is applied. It is permanently stored
in hardware and checks that the hardware is working.
• The Bootstrap loads the Firmware from ROM. Firmware provides the low-level instructions needed to
initialise the hardware.
• The Firmware loads the Operating System from secondary storage into RAM.
• The Operating System then allows Application Software to be run.
This can be summarised as: Bootstrap → Firmware → Operating System → Application Software
4.2 Operating System (OS)
Operating System: A type of system software that manages all of the hardware and software on a
computer. It provides the platform for applications to run and enables the user to interact with the
computer.
Examples: Windows, Linux, macOS (desktop/laptop); Android, iOS (mobile phones).
Functions of an Operating System
1. Providing a User Interface:
The OS provides a method for the user to interact with the computer.
• Graphical User Interface (GUI) — Uses windows, icons, menus, and pointers (the WIMP
environment). The user interacts by clicking icons and navigating menus. Intuitive and easy to learn
— suitable for novice users. Examples: Windows, macOS, Android.
• Command Line Interface (CLI) — The user types text commands directly. The computer executes the
commands. Commands must be exact — any error and the command fails. Requires expertise but is
very powerful and efficient for advanced users. Example: Linux terminal, Windows Command Prompt.
• Natural Language Interface — The user speaks or types commands in everyday language. The OS
analyses the input and determines the correct action. Examples: Apple Siri, Amazon Alexa, Microsoft
Cortana.
2. Managing Files:
The OS allows users to create, open, save, move, copy, rename, delete, and sort files. It also allows the
creation of directories (folders) to organise files. File management enables the storage of data in an organised
structure on secondary storage.
3. Managing Peripherals and Drivers:
Peripheral devices (printers, keyboards, mice, etc.) are built by different manufacturers and may use different
binary interpretations. A driver is a software program that translates between the OS and a specific peripheral
device — converting instructions into a format the device understands and vice versa. The OS manages the
installation of drivers and ensures data is sent to/from peripherals correctly.
4. Managing Memory:
The OS is responsible for managing the movement of data to and from RAM. It allocates appropriate amounts
of memory to each running process, ensures processes have enough memory to perform their tasks, and
prevents two processes from attempting to access the same memory location simultaneously (which would
cause conflicts and crashes).
5. Managing Multitasking:
A single processor core can only execute one instruction at a time. However, modern computers appear to run
many programs simultaneously (e.g. listening to music while browsing the internet and editing a document).
The OS achieves this by switching between tasks so rapidly that it appears seamless to the user. The OS
decides which process runs next, how long it runs before switching, and manages this using a technique
involving interrupts.
6. Managing Interrupts:
An interrupt is a signal sent to the processor telling it that something requires its immediate attention. The OS
manages interrupts to allow multitasking and to respond to hardware events.
7. Managing User Accounts:
The OS allows multiple user accounts to be set up on the same computer. Each account can have its own
settings, preferences, and files. The OS uses usernames and passwords to restrict access, keeping each
user's data separate and secure.
8. Providing a Platform for Running Applications:
The OS fetches and executes instructions from application software, allowing programs written in any
language to run on the computer, regardless of who created them.
4.3 Interrupts
Interrupt: A signal sent to the processor to inform it that something requires its attention. An interrupt can
be generated by software or hardware.
Examples of software interrupts and hardware interrupts:
Software Interrupts Hardware Interrupts
Division by zero error Data input (e.g. key pressed on keyboard, mouse
click)
Two processes attempting to access the same Error from hardware (e.g. printer out of paper)
memory location
Program request for input Hardware failure
Output required by a program Hard drive signalling it has read data
Data required from memory New hardware device connected (e.g. USB
inserted)
Interrupt Handler (IH): A program that manages the interrupt queue. It organises pending interrupts by
priority level. High-priority interrupts (e.g. hardware failure) need immediate attention; low-priority
interrupts (e.g. key pressed) are less urgent.
Interrupt Service Routine (ISR): The specific sequence of instructions that handles a particular type of
interrupt. When an interrupt is processed, the relevant ISR is called and runs to completion.
Interrupt handling process:
• When the processor completes its current fetch-decode-execute cycle, it checks the interrupt queue.
• It checks whether there is an interrupt with higher priority than the current task.
• If there is a higher-priority interrupt: the current process is paused and its state is saved. The source
of the interrupt is identified. The relevant Interrupt Service Routine (ISR) is called and executed.
• When the ISR completes, the saved process is restored and continues from where it left off.
• If no higher-priority interrupt exists, the processor continues with the next FDE cycle.
4.4 Programming Languages
High-Level Languages
High-level language: A programming language that uses human-readable, English-like commands.
Examples of high-level language instructions: IF, WHILE, PRINT, INPUT. These languages are
independent of any particular computer's hardware.
High-level languages are:
• Easier to write, read, understand, and debug for humans.
• Portable — a program written on one computer can run on a different computer without rewriting it
(machine independent).
• One statement typically represents many machine code instructions.
• Cannot directly manipulate hardware memory locations.
Examples: Python, Java, [Link], C++, Pascal
Low-Level Languages
Low-level language: A programming language closer to machine code. Includes assembly language and
machine code (binary).
Machine Code:
The only language a processor can execute directly — pure binary (1s and 0s). Every instruction is a binary
number. Machine code is non-portable: a program written in machine code for one type of processor may not
run on a different processor.
Assembly Language:
Uses short text codes called mnemonics to represent machine code instructions. For example, STO (store),
LDD (load), ADD (add). Each assembly language instruction corresponds to exactly one machine code
instruction. Must be converted to machine code by an assembler before it can run. Still non-portable —
assembly language is specific to a particular processor's instruction set.
Example: count = count + 1 in high-level = 3 assembly language instructions: LDD count / ADD 1 / STO count
High-Level Language Low-Level Language
Easier to read, write and understand. More difficult to read, write and understand.
Easier to debug. Harder to debug.
Portable — works on many types of computer. Non-portable — specific to a particular CPU.
Must be translated before it can run. Machine code runs directly. Assembly must be
assembled.
One statement = many machine code instructions. One statement = one machine code instruction.
Cannot directly manipulate hardware. Can directly access hardware memory locations
— more efficient in memory and speed for specific
tasks.
4.5 Translators
Translator: Software that converts code written in one programming language into another — typically
converting a high-level or assembly language into machine code (binary).
Assembler: Converts assembly language programs into machine code. One assembly language
instruction is converted into exactly one machine code instruction.
Interpreter: Converts a high-level language program into machine code one line at a time. For each line:
it reads the line, checks it for syntax errors, and if correct, immediately executes it before moving to the
next line. If a syntax error is found, the interpreter stops and reports the error immediately. The program
does NOT continue until the error is fixed. Does NOT produce an executable file — the source code must
be present every time the program is run.
Best used when: writing and testing a program, because errors are identified and corrected as you go.
Compiler: Converts an entire high-level language program into machine code in one go. It reads through
all the code line by line. If any syntax errors are found, they are ALL reported at the end — the program
does not run at all until every error is fixed. If there are no errors, the compiler produces an executable file
(.exe) — a standalone program in machine code. This executable can be run without the original source
code and without requiring the compiler to be present.
Best used when: the program is complete and ready to be distributed to users.
Feature Interpreter Compiler
How it translates One line at a time — checks and All lines at once — translates the
executes each line before moving on. entire program before executing.
Error reporting Stops at the first error and reports it Reports all errors together at the
immediately. end.
Execution Can run incomplete programs. Only runs if ALL errors are
corrected.
Executable file Does NOT produce one. Source code Produces an executable file that
needed every time. runs independently.
Speed of execution Slower — must re-translate every time Faster — no re-translation needed
the program runs. after first compilation.
Best use During development and testing. When the program is finished and
ready for distribution.
PART 2 — 40 MARKS: Short answers and scenario-
based questions
CHAPTER 7: ALGORITHM DESIGN AND PROBLEM
SOLVING
7.1 What Is an Algorithm?
Algorithm: A precise, unambiguous, step-by-step set of instructions that solves a problem or completes a
task. Algorithms are not limited to computers — they exist in everyday life (a recipe is an algorithm;
mathematical procedures are algorithms). For computers, algorithms are written as programs — precise
instructions the processor executes.
Different types of programming language can be used to implement algorithms:
• Procedural — instructions run in order; uses subroutines (procedures and functions). Most commonly
taught.
• Object-oriented — programs are organised around 'objects' that have attributes (data) and methods
(actions).
• Event-driven — code only runs in response to events (e.g. button clicks).
• Declarative — declares facts/rules and queries are answered based on those rules.
7.2 Program Development Life Cycle (PDLC)
Program Development Life Cycle: A structured, organised plan followed when creating a computer
program. It ensures programs are built methodically and correctly.
The four stages are:
• Analysis — investigating the problem; identifying what the program must do; decomposing the
problem.
• Design — planning how the program will work; creating structure diagrams, flowcharts, and
pseudocode.
• Coding — writing the actual program in a chosen programming language.
• Testing — running the program with various data to ensure it works correctly, does not crash, and
meets requirements.
Analysis — Decomposition
Decomposition: The process of breaking a large, complex problem down into smaller, more manageable
sub-problems (sub-systems). Each sub-problem can then be tackled and solved independently. When all
sub-problems are solved and combined, the whole problem is solved.
Structure Diagram: A hierarchical diagram that visually shows how a program has been decomposed
into its sub-programs. The name of the whole program goes at the top. Below it, the sub-programs are
shown in boxes. Each sub-program can be broken down further into its own boxes. There is no limit to
how many levels of decomposition there can be.
Example: A calculator program might be decomposed into: Input (number1, symbol, number2) → Process (+,
-, *, /) → Output (result). Each of these can be broken down further.
7.3 Flowcharts
Flowchart: A diagrammatic (visual) representation of an algorithm. It uses standardised shapes
connected by arrows to show the flow of execution through the algorithm. Flowcharts can be used to plan
programs before coding, or to explain how existing programs work.
Shape Name Purpose and Rules
Oval / Rounded Start / Stop Marks the beginning and end of the flowchart. A
rectangle flowchart must have exactly one Start (with one
arrow coming out) and at least one Stop (with one
arrow going in). No other shapes use this symbol.
Parallelogram Input / Output Represents data being entered by the user
(INPUT) or displayed to the user (OUTPUT). One
arrow in, one arrow out.
Rectangle Process Represents an action being performed — usually a
calculation or assignment (e.g. x = x + 1). One
arrow in, one arrow out.
Diamond Decision Represents a question with exactly two possible
outcomes: YES and NO. One arrow goes into the
diamond; two arrows come out — one labelled
YES and one labelled NO. The condition inside is
a comparison (e.g. Is x > 10?).
Arrow / Flow line Flow direction Shows the direction of flow from one shape to the
next. Must always have an arrowhead. All shapes
must be connected — no dead ends.
Important flowchart rules:
• Every box must have at least one arrow entering and one leaving (except Start which has no entry,
and Stop which has no exit).
• Decision boxes must ALWAYS have exactly two output arrows labelled YES and NO.
• Loops are created by having an arrow from a later box go back to an earlier box.
• Content inside each shape can be written in plain English or as pseudocode statements.
7.4 Pseudocode
Pseudocode: A way of writing an algorithm that uses programming-like keywords and structures (IF,
WHILE, FOR, INPUT, OUTPUT etc.) but does not follow the exact syntax of any real programming
language. It is not meant to be run on a computer — it is used to plan and communicate the logic of an
algorithm. Any programmer should be able to read pseudocode and convert it into their chosen
programming language.
There is no single fixed pseudocode standard — different textbooks and exam boards use slightly different
formats. What matters is that the logic is clear and unambiguous. Note: syntax in pseudocode does not have
to be perfect, but the logic must be correct.
Concept Pseudocode Notes
Input INPUT variableName Reads data the user types and
stores it in the variable.
Output OUTPUT "message" or OUTPUT Displays text or the value of a
variable variable to the user.
Assignment variable <- value Assigns a value to a variable.
Some formats use = for
assignment.
Concatenation output OUTPUT "Hello " & Name Joins strings together for output. &
, , or + all acceptable in
pseudocode.
IF statement IF condition THEN ... ENDIF Runs the code only if the condition
is TRUE.
IF-ELSE IF condition THEN ... ELSE ... Runs first block if TRUE, second
ENDIF block if FALSE.
ELSEIF IF c1 THEN ... ELSEIF c2 Tests multiple conditions in
THEN ... ELSE ... ENDIF sequence.
CASE statement CASE OF variable val1: ... Checks a variable against a list of
val2: ... OTHERWISE: ... specific values.
ENDCASE
FOR loop FOR var <- start TO end ... Runs a fixed number of times.
NEXT var
FOR loop with STEP FOR var <- start TO end STEP n Changes the increment amount.
STEP -1 counts down.
WHILE loop WHILE condition DO ... Runs while condition is TRUE.
ENDWHILE Checks condition BEFORE each
run. May never run.
REPEAT-UNTIL REPEAT ... UNTIL condition Runs UNTIL condition becomes
TRUE. Checks AFTER each run.
Always runs at least once.
AND, OR, NOT IF x > 0 AND x < 10 Boolean operators for combining
conditions.
Comparison operators = <> < > <= >= = means equal; <> means not
equal.
Valid vs Invalid Pseudocode
Valid Pseudocode Invalid Pseudocode
INPUT Value Input the value X (too vague — not structured)
FOR X <- 0 TO 9 Loop 10 times (not a pseudocode statement)
OUTPUT Value + X In each loop output the loop number added to
value (not structured)
IF numl > num2 THEN OUTPUT(numl) ELSE If numl is greater than num2 output numl else
OUTPUT(num2) ENDIF output num2 (can be acceptable but better
structured)
7.5 Trace Tables
Trace table: A structured table used to manually trace through an algorithm step by step, recording how
the values of variables change as each instruction is executed. Trace tables are used to: (a) identify and
fix errors (bugs) in an algorithm; (b) determine what an algorithm does by following its logic; (c) verify that
an algorithm produces the correct output.
How to complete a trace table:
• Create one column per variable in the algorithm, plus an OUTPUT column if needed.
• Read through the algorithm line by line, executing each instruction manually.
• Each time a variable's value changes, write the new value in its column.
• When you reach a loop's end, go back to the start of the loop and repeat.
• A row represents the state after processing each significant step.
• Record any output produced in the OUTPUT column.
Worked Example — Trace with inputs 4, 3, 2, 1, 0:
count <- 0
total <- 0
WHILE inputValue <> 0 DO
INPUT inputValue
total <- total + inputValue
count <- count + 1
ENDWHILE
OUTPUT total
count inputValue total OUTPUT
0 — 0
0 4 0
1 4 4
1 3 4
2 3 7
2 2 7
3 2 9
3 1 9
4 1 10
4 0 10 10
7.6 Common Algorithms — Linear Search and Bubble Sort
Linear Search
Linear search: A search algorithm that checks each item in a list one at a time, starting from the first, until
it either finds the target value or reaches the end of the list without finding it.
How it works:
• Start at index 0 (the first element).
• Compare the current element to the search value.
• If they match — the item is found. Record or output the index.
• If they do not match — move to the next element (increment index).
• If the end of the list is reached without finding the value — the item is not in the list.
Pseudocode (efficient version with early stopping):
Found <- FALSE
index <- 0
WHILE Found = FALSE AND index < LENGTH(array) DO
IF array[index] = searchValue THEN
OUTPUT "Found at index " & index
Found <- TRUE
ELSE
index <- index + 1
ENDIF
ENDWHILE
Note: A simpler version uses a FOR loop to check every element even after finding the value — this is less
efficient but easier to code and useful if the value may appear multiple times.
Bubble Sort
Bubble sort: A sorting algorithm that repeatedly compares adjacent pairs of values in a list and swaps
them if they are in the wrong order. After each full pass through the list, the largest unsorted value has
'bubbled' to its correct position at the end. The process repeats until the list is sorted.
How it works:
• Compare element at index 0 with element at index 1.
• If they are in the wrong order, swap them.
• Move to the next pair: compare index 1 and index 2. Swap if needed.
• Continue to the end of the list. This is one complete pass.
• Repeat from the beginning for another pass.
There are two ways to decide when to stop:
• Version 1 (simple): run exactly (number of elements - 1) passes. If there are 10 elements, run 9
passes regardless of whether the list is already sorted.
• Version 2 (efficient): stop early if a complete pass is made with no swaps — the list is already in order.
Worked example — sorting [5, 3, 9, 4]:
Pass 1: Compare 5,3 → swap → [3,5,9,4]. Compare 5,9 → no swap. Compare 9,4 → swap → [3,5,4,9]
Pass 2: Compare 3,5 → no swap. Compare 5,4 → swap → [3,4,5,9]. Compare 5,9 → no swap.
Pass 3: Compare 3,4 → no swap. Compare 4,5 → no swap. Compare 5,9 → no swap. No swaps → sorted!
Sorted result: [3, 4, 5, 9]
7.7 Testing and Test Data
When a program is complete, it must be tested to ensure it: works correctly, does not crash, and meets all
requirements. Appropriate test data must be carefully chosen to cover all situations.
Test Data Type Definition Example (program accepts ages 10–
100)
Normal Data the program should accept 50, 30, 75
and process correctly. Typical
data a real user would enter.
Abnormal (Invalid) Data the program should reject — 9, -1, 200, "abc", 12.5
outside the expected range or the
wrong data type entirely.
Extreme Data at the very boundaries of 10 (lowest accepted), 100 (highest
what the program accepts — the accepted)
lowest and highest valid values.
Boundary Data on either side of each 9 and 10 (around lower bound), 100 and
boundary — one value just inside 101 (around upper bound)
and one just outside the accepted
range.
Note: Extreme and boundary test data can overlap. For example, the value 10 may count as both extreme
(lowest accepted) and boundary (lowest accepted). This is valid — these are categories to ensure all edges
are tested.
Example 2: Password must be at least 8 characters
Test Type Example Data
Normal "abcdefgh" (8 chars), "password123" (11 chars)
Abnormal "abc" (3 chars), "1234567" (7 chars)
Extreme "abcdefgh" (exactly 8 chars)
Boundary "abcdefg" (7 chars — just too short), "abcdefgh" (8 chars — just long enough)
CHAPTER 8: PROGRAMMING
8.1 Programming Concepts — Variables and Constants
Variable: A named memory location in a program that stores a value which can change while the
program is running. A variable has an identifier (name) and a data type.
Constant: A named memory location whose value is set once at the beginning and cannot be changed
during the program. Using constants makes programs clearer and easier to maintain — if the value needs
to change, it only needs updating in one place.
Assignment — storing a value in a variable:
Number <- 10
Colour <- "red"
Price <- 22.4
Declaring a constant:
CONSTANT Pi <- 3.14159
CONSTANT MaxScore <- 100
8.2 Data Types
Every variable and constant must have a data type that determines what kind of value it holds.
Data Type Description Example Values
Integer Whole numbers only. No decimal points. 1, 23, -300, 0, 45000
Can be positive, negative, or zero.
Real Numbers with at least one decimal 1.2, 23.0, -20.49, 3949.38
(Float/Double) place. Used for measurements, prices,
averages.
String Any sequence of characters: letters, "hello", "123", "help!", "J Smith"
digits, symbols. Always enclosed in
speech marks.
Char A single character only. Enclosed in "h", "9", "?", "A"
speech marks.
Boolean Can only hold one of two values: TRUE TRUE, FALSE
or FALSE. Used for flags and conditions.
Note: The same value can sometimes be stored as more than one data type. For example, the value 10 can
be an integer or a real (10.0) or even a string ("10"). Choosing the most appropriate type matters — you can't
perform arithmetic on a string.
Type casting — converting between data types: Number <- INT("123") converts string "123" to integer 123.
Value <- STRING(22.4) converts number to string.
8.3 Input and Output
Output
OUTPUT displays information to the user, usually on screen.
OUTPUT "Hello World" (output a fixed string)
OUTPUT 20 (output a number)
OUTPUT Name (output the value of a variable)
OUTPUT "Hello ", Name (output text joined with a variable)
OUTPUT "There are ", Balloon , " balloons" (multiple items)
Concatenation: Joining two or more strings (or a string and a variable) together. In pseudocode, & or , or
+ can all be used to concatenate. Example: OUTPUT "Hello " & Name would display Hello followed by
the value of Name.
Always include a space inside the speech marks when needed, otherwise words will join without spaces: e.g.
OUTPUT "Hello" & Name would give HelloAlex, not Hello Alex.
Input
INPUT reads data that the user types and stores it in a variable.
INPUT Number (stores user's input in Number)
OUTPUT "Enter a word"
INPUT Word (prompts then reads input)
Always store input in a variable, otherwise the entered data is immediately lost.
8.4 Arithmetic and Comparison Operators
Arithmetic Operators
Operator Operation Example Result
+ Addition 10 + 2 12
- Subtraction 10 - 2 8
* Multiplication 10 * 2 20
/ Division (gives decimal 10 / 4 2.5
result)
DIV Integer division (ignores DIV(11, 9) 1
remainder)
MOD Modulus (gives remainder MOD(11, 9) 2
only)
^ Power of (exponentiation) 2^3 8
MOD vs DIV explained:
• DIV(20, 7): 20 ÷ 7 = 2.857... → DIV keeps only the whole number → answer = 2
• MOD(20, 7): 7 × 2 = 14; 20 - 14 = 6 → MOD gives the remainder → answer = 6
• Special use of MOD: MOD(number, 2) = 0 means the number is even; MOD(number, 2) = 1 means
odd.
Brackets (parentheses) change the order of operations — expressions inside brackets are calculated first:
Total <- 1 + (2 * 3) gives 7 (multiply first: 2*3=6, then 1+6=7)
Total <- (1 + 2) * 3 gives 9 (add first: 1+2=3, then 3*3=9)
Comparison (Logical) Operators
Operator Meaning Example Result
= or == Equal to 10 = 10 TRUE
<> or != Not equal to 10 <> 2 TRUE
< Less than 10 < 11 TRUE
<= Less than or equal to 10 <= 10 TRUE
> Greater than 11 > 10 TRUE
>= Greater than or equal to 50 >= 70 FALSE
Boolean Operators (Combining Conditions)
Operator Behaviour Example Result
AND Both conditions must be TRUE. 1=1 AND 2=2 TRUE
AND Both conditions must be TRUE. 1=1 AND 1>2 FALSE (right
side is false)
OR At least one condition must be 1=1 OR 1>2 TRUE (left side
TRUE. is true)
OR At least one condition must be 1<0 OR 0<-1 FALSE (both
TRUE. false)
NOT Reverses the Boolean value. NOT(1=1) FALSE (1=1 is
TRUE,
reversed =
FALSE)
NOT Reverses the Boolean value. NOT(1=2) TRUE (1=2 is
FALSE,
reversed =
TRUE)
8.5 Sequence
Sequence: The simplest programming construct. Instructions are executed one after another in the exact
order they are written. No decisions, no repetition — just a straight line from top to bottom.
Example:
OUTPUT "Enter a colour"
INPUT Colour
OUTPUT "Enter your name"
INPUT Name
OUTPUT Name , " your favourite colour is " , Colour
These 5 lines run in exactly this order, once each.
8.6 Selection (IF and CASE Statements)
Selection: A programming construct where a condition is checked and the result (TRUE or FALSE)
determines which block of code runs, or whether any code runs at all.
IF Statement (Simple)
Runs the code only if the condition is TRUE. If FALSE, nothing happens.
IF condition THEN
statements
ENDIF
Example:
Num1 <- 10
IF Num1 = 10 THEN
OUTPUT "True"
ENDIF
IF-ELSE Statement
If TRUE runs the first block; if FALSE runs the ELSE block. Always one or the other runs.
IF condition THEN
statements if TRUE
ELSE
statements if FALSE
ENDIF
Example:
IF Guess = Number THEN
OUTPUT "Correct!"
ELSE
OUTPUT "Incorrect!"
ENDIF
ELSEIF Statement
Allows testing multiple conditions in sequence. The first TRUE condition's block runs, then the IF statement
ends.
IF condition1 THEN
statements if condition1 is TRUE
ELSEIF condition2 THEN
statements if condition1 FALSE and condition2 TRUE
ELSE
statements if ALL conditions are FALSE
ENDIF
Example — output grade:
IF Age < 14 THEN
OUTPUT "You are not old enough"
ELSEIF Age < 16 THEN
OUTPUT "You need an adult present"
ELSE
OUTPUT "You are old enough"
ENDIF
CASE Statement (SELECT CASE)
Used when you want to compare a single variable against many specific values. More efficient than many
ELSEIFs when checking one variable.
CASE OF variable
value1 : statements
value2 : statements
value3 : statements
OTHERWISE : default statements
ENDCASE
Example — menu system:
OUTPUT "Enter 1-5"
INPUT Choice
CASE OF Choice
1 : OUTPUT "Menu option 1"
2 : OUTPUT "Menu option 2"
3 : OUTPUT "Menu option 3"
OTHERWISE : OUTPUT "Invalid choice"
ENDCASE
8.7 Iteration (Loops)
Iteration: A programming construct where a block of code is repeated multiple times. This avoids writing
the same code over and over. Also called a loop.
FOR Loop (Count-Controlled)
Count-controlled loop: Runs a fixed, predetermined number of times. A counter variable starts at a
given value and increases by 1 (or by STEP n) each iteration until it reaches the end value.
FOR counter <- startValue TO endValue
statements
NEXT counter
Examples:
FOR X <- 1 TO 10 (runs 10 times: X = 1,2,3,...,10)
OUTPUT X
NEXT X
FOR Count <- 1 TO 12 (prints the 12 times table)
OUTPUT Count * 12
NEXT Count
FOR Number <- 10 TO 1 STEP -1 (counts down from 10 to 1)
OUTPUT Number
NEXT Number
FOR Value <- 11 TO 20 STEP 0.5 (increments by 0.5)
OUTPUT Value
NEXT Value
STEP 1 = increase by 1 each time (default). STEP -1 = decrease by 1 (count down). STEP 0.5 = increase by
0.5.
WHILE Loop (Pre-Condition Loop)
Pre-condition loop: The condition is checked BEFORE each execution of the loop body. If the condition
is FALSE at the start, the loop body may never run at all. The loop continues while the condition is TRUE
and stops when it becomes FALSE.
WHILE condition DO
statements
ENDWHILE
Examples:
Number <- 1
WHILE Number < 11 DO (outputs 1 to 10)
OUTPUT Number
Number <- Number + 1
ENDWHILE
Number <- 5
Guessed <- FALSE
WHILE Guessed = FALSE DO (keep asking until correct)
OUTPUT "Guess the number"
INPUT Guess
IF Guess = Number THEN
Guessed <- TRUE
ENDIF
ENDWHILE
Important: if the condition is FALSE before the loop starts, the body never executes.
REPEAT-UNTIL Loop (Post-Condition Loop)
Post-condition loop: The condition is checked AFTER each execution of the loop body. Therefore, the
loop body always runs at least once, regardless of the condition. The loop continues until the condition
becomes TRUE.
REPEAT
statements
UNTIL condition
Examples:
REPEAT
OUTPUT "Do you want to stop?"
INPUT Answer
UNTIL Answer = "Yes"
NumberToGuess <- 15
REPEAT
OUTPUT "Guess the number"
INPUT Guess
UNTIL Guess = NumberToGuess
Key difference: WHILE may not run at all if condition is immediately false. REPEAT always runs at least once.
Converting Between Loop Types
Any FOR loop can be rewritten as a WHILE loop. Three steps:
• Step 1: Declare and initialise the counter variable before the loop.
• Step 2: Write the WHILE condition using the end value.
• Step 3: Manually increment the counter inside the loop.
Example — convert FOR loop to WHILE:
FOR X <- 1 TO 10 becomes:
OUTPUT X
NEXT X
X <- 1 (Step 1: initialise)
WHILE X < 11 DO (Step 2: condition)
OUTPUT X
X <- X + 1 (Step 3: increment)
ENDWHILE
8.8 Totalling
Totalling: Accumulating a running total by repeatedly adding new values to a sum variable.
Required elements for a totalling program:
• Initialise the total variable to 0 before the loop.
• Inside the loop: total <- total + newValue
Example — total 10 user inputs:
Total <- 0
FOR Counter <- 1 TO 10
OUTPUT "Enter a number"
INPUT Number
Total <- Total + Number
NEXT Counter
OUTPUT "The total is " & Total
8.9 Counting
Counting: Keeping a running count of how many times something occurs (e.g. how many values meet a
condition).
Required elements for a counting program:
• Initialise the count variable to 0.
• Increment the counter by 1 each time the counted condition is met: count <- count + 1
Example — count numbers > 50 in an array of 100 elements:
Count <- 0
FOR X <- 0 TO 99
IF ArrayData[X] > 50 THEN
Count <- Count + 1
ENDIF
NEXT X
OUTPUT Count
8.10 String Manipulation
Strings are sequences of characters. The following built-in functions allow manipulation of strings.
IMPORTANT: In pseudocode, string indexing starts at 0. The first character is at position 0.
Function Syntax What It Does Example
LENGTH LENGTH(string) Returns the number of LENGTH("Hello") → 5 |
characters in the string LENGTH("0123") → 4
(including spaces and
symbols).
SUBSTRING SUBSTRING(string, start, Extracts a portion of the SUBSTRING("Hello", 0, 1)
length) string, starting at the given → "H" |
index and taking the given SUBSTRING("Goodbye", 4,
number of characters. 3) → "bye"
UPPER UPPER(string) Converts all characters in UPPER("Hello") →
the string to uppercase. "HELLO"
LOWER LOWER(string) Converts all characters in LOWER("HELLO") →
the string to lowercase. "hello"
Concatenation str1 & str2 Joins two strings together. "Hello" & " World" → "Hello
World"
Worked examples:
InputString <- INPUT("Enter a string")
StringLength <- LENGTH(InputString)
OUTPUT InputString & " is " & StringLength & " characters long"
StringData <- "Goodbye"
NewMessage <- SUBSTRING(StringData, 0, 4) → "Good"
OUTPUT NewMessage
OUTPUT "Enter a message"
INPUT StringInput
FOR Count <- 0 TO LENGTH(StringInput) - 1 (output each char one at a time)
Character <- SUBSTRING(StringInput, Count, 1)
OUTPUT Character
NEXT Count
NewString <- SUBSTRING(StringInput, LENGTH(StringInput) - 3, 3) (last 3 chars)
Practical use: Using LENGTH and SUBSTRING together, you can check if a password meets requirements
(e.g. at least 8 characters, contains specific character types).
8.11 Nested Statements
Nested statement: A selection or iteration construct that is placed inside another selection or iteration
construct. This could be: an IF inside another IF, a loop inside an IF, an IF inside a loop, or a loop inside a
loop.
The key rule: if a construct starts inside another construct, it must also finish inside that same construct. The
nesting structure must be properly closed.
Nested IF
Example — classify a score:
IF Score >= 80 THEN
IF Score >= 95 THEN
OUTPUT "Distinction"
ELSE
OUTPUT "Merit"
ENDIF
ELSE
OUTPUT "Pass or Fail"
ENDIF
IF Inside a Loop
Example — count numbers over 10 and equal to 10:
MoreThan10 <- 0
EqualTo10 <- 0
FOR X <- 0 TO 99
OUTPUT "Enter a number"
INPUT Number
IF Number > 10 THEN
MoreThan10 <- MoreThan10 + 1
ELSEIF Number = 10 THEN
EqualTo10 <- EqualTo10 + 1
ENDIF
NEXT X
OUTPUT "More than 10: " & MoreThan10
OUTPUT "Equal to 10: " & EqualTo10
Loop Inside a Loop (Nested Loops)
The inner loop runs completely for each single iteration of the outer loop.
Example — multiplication table:
FOR i <- 1 TO 3
FOR j <- 1 TO 3
OUTPUT i * j
NEXT j
NEXT i
This produces 9 outputs (3×3 = 9 combinations).
REPEAT Loop for Input Validation (Common Pattern)
A very common and important pattern — keep asking for input until valid data is entered:
REPEAT
OUTPUT "Enter a number between 1 and 10"
INPUT Score
IF Score < 1 OR Score > 10 THEN
OUTPUT "Invalid! Please try again."
ENDIF
UNTIL Score >= 1 AND Score <= 10
This always runs at least once. If the user enters invalid data, it outputs an error and loops. It exits only when
valid data (between 1 and 10) is entered.
CHAPTER 9: DATABASE
9.1 Database Structure
Database: A structured collection of related data stored and organised so it can be efficiently searched,
sorted, and retrieved. Almost every organisation uses databases — businesses store customer data,
schools store student records, websites store user accounts.
Key Database Terminology
Term Definition Example
Table A collection of data about one type of A 'Books' table, a 'Students' table, a
object/entity. A database may have 'Orders' table
many tables.
Field An individual piece of data (attribute) BookName, Author, Price,
about each object — one column in the DateOfBirth, StudentID
table.
Record All the fields for one specific object — All details about the book 'Night
one complete row in the table. Stars': its ID, name, author, price,
genre
Primary Key A field whose value uniquely identifies StudentID = 101 exists only once. If
each record. No two records can share no natural unique field exists, add an
the same primary key value. Cannot be ID field.
null (empty).
Example database — Books table:
BookID BookName Author Publisher Genre Fiction
1 Picking daisies J. Frank Cambridge Horticulture Gardening False
2 Night stars K. Mars Si-fi books Science fiction True
3 Dreaming of the sun P. Yu Si-fi books Science fiction True
4 Cooking for fun W. Crisp Cookery Penguin Cookery False
In this example, BookID is the primary key. None of the other fields (BookName, Author, etc.) are suitable as
primary keys because duplicate values are possible — two books could have the same name, or one author
could write multiple books.
Database Data Types
Data Type Description Example Values
Text / Alphanumeric Any combination of letters, digits, and "Hello", "2JK8D", "J Smith",
symbols. Numbers stored as text cannot "2198"
be used in arithmetic.
Character A single letter, digit, or symbol only. "H", "y", "1", "?"
Boolean Only two possible values: True or False True, False
(or Yes/No).
Integer Whole numbers only. 123, 999, 0, -1928
Real Numbers with at least one decimal 0.0, 1.2, 9.99, 100.92, -2.93
place.
Date/Time A date and/or time value. 01/01/2025, 08:30, 15/03/2024
16:00
Designing a Single-Table Database
When designing a database, follow these three steps:
Step 1 — Identify the fields:
Read the description carefully. For each piece of information to store, create one field with an appropriate
name.
Step 2 — Choose the data type for each field:
Look at the example data. If it contains letters → Text. If it's a whole number → Integer. If it has a decimal →
Real. If it's Yes/No → Boolean. If it's a single character → Character.
Step 3 — Choose a primary key:
Check if any field is naturally unique for every record. If no field is naturally unique (which is common), add a
new ID field and make it the primary key.
Example — wool shop database:
The shop stores: name, colour, weight (e.g. 2), price (e.g. $3.99), quantity in stock (e.g. 23).
Field Name Example Data Data Type Reasoning
IDNumber 101, 102, 103... Text Added as primary key — unique
ID for each item
ItemName "Sparkle wool" Text Has more than one letter so it's
Text (not Char)
Colour "red" Text Multiple letters — Text
Weight 2 Integer Whole number — no decimal
Price 3.99 Real Has a decimal — Real
Quantity 23 Integer Whole number — Integer
9.2 SQL — Structured Query Language
SQL (Structured Query Language): A standard programming language used to query and manipulate
databases. SQL is almost universal — it works across most database systems. This means that anyone
who knows SQL can work with databases on different platforms.
For this specification, you need to know how to: SELECT fields FROM a table; and filter results using
WHERE.
9.3 SELECT ... FROM
The SELECT ... FROM command retrieves data from specified fields in a table.
Select a single field:
SELECT BookName
FROM Books
Returns: all values from the BookName column for every record in the Books table.
Select multiple fields (separate with commas):
SELECT BookName, Genre
FROM Books
Returns: BookName and Genre columns together. Each record appears on a new line.
Select all fields:
SELECT *
FROM Books
The asterisk (*) means 'all fields'. Returns every column.
IMPORTANT RULES:
• Field names and table names are CASE SENSITIVE — must be spelled exactly as defined.
• Field names in SELECT are separated by commas.
• No comma at the very end of the field list.
• The order of fields in SELECT determines the order they appear in the output.
• Each record in the result appears on a new line.
9.4 SELECT ... FROM ... WHERE
Adding WHERE filters the results, returning only records that match a specified condition.
SELECT field(s)
FROM TableName
WHERE condition
Single Condition — Comparison Operators
Operator Meaning Example WHERE clause What it returns
= Equal to WHERE Fiction = True Only records where
Fiction is True
<> Not equal to WHERE Posted <> Yes Records where
Posted is not Yes
< Less than WHERE NumberItems < 10 Records with fewer
than 10 items
<= Less than or equal to WHERE TotalCost <= 6.00 Records with cost of
$6 or less
> Greater than WHERE NumberItems > 20 Records with more
than 20 items
>= Greater than or equal WHERE TotalCost >= 3.99 Records with cost
to $3.99 or more
Examples using the Orders table (fields: OrderID, FirstName, LastName, NumberItems, TotalCost,
Posted):
SELECT FirstName, LastName, Posted
FROM Orders
WHERE Posted = Yes
SELECT OrderID, Posted
FROM Orders
WHERE Posted <> Yes
SELECT FirstName, LastName
FROM Orders
WHERE NumberItems > 20
Multiple Conditions — Boolean Operators
Operator Behaviour Example
AND BOTH conditions must be TRUE WHERE Fiction = TRUE AND Cost < 3.99
for a record to be returned. A (only books that are fiction AND cost less than
record that is true for one $3.99)
condition but not the other is NOT
returned.
OR At least ONE condition must be WHERE Genre = "Cookery" OR Price < 1.00
TRUE. Records matching either (books that are cookery OR cost less than $1)
condition (or both) are returned
once each.
Examples:
SELECT Name, Cost
FROM PRODUCTS
WHERE Type = "Chocolate" AND Cost < 1.00
SELECT StudentID, Subject, Grade
FROM MARKS
WHERE Subject = "Science" OR Grade = "Merit"
CHAPTER 10: BOOLEAN LOGIC
10.1 The Role of Logic Gates
Every component in a computer runs on electricity. To process binary data (which has two values: 0 and 1),
the computer needs the electricity to exist in two states: high voltage (representing 1) and low voltage
(representing 0).
Logic gates are tiny electronic components that control the flow of electricity. Each gate takes one or two
binary inputs and produces one binary output, following specific logical rules. Computers contain thousands of
logic gates — together they allow all data processing to occur.
Logic gate: A small electronic component that takes binary input(s) and produces a binary output based
on a defined logical rule.
Truth table: A table showing all possible combinations of input values and the corresponding output value
for a logic gate or circuit.
Logic expression: A mathematical formula using Boolean operators that describes what a logic circuit
does. Example: X = A AND B
The word 'Boolean' refers to a two-state system (True/False, 1/0) — named after mathematician George
Boole.
10.2 The NOT Gate
The NOT gate (also called an inverter) has ONE input and ONE output. It reverses (inverts) the input.
Whatever goes in comes out as the opposite.
Rule: Output is 1 when input is 0. Output is 0 when input is 1.
A (Input) X (Output)
0 1
1 0
Logic expression: X = NOT A
Alternative notation: X = Ā (a line over the letter means NOT)
10.3 The AND Gate
The AND gate has TWO inputs and ONE output. The output is 1 ONLY when BOTH inputs are 1. If either
input (or both) is 0, the output is 0.
Think of it as: you AND your friend both need a ticket to enter.
A B X = A AND B
0 0 0
0 1 0
1 0 0
1 1 1
Logic expression: X = A AND B
Alternative notation: X = A.B (a dot between A and B means AND)
10.4 The OR Gate
The OR gate has TWO inputs and ONE output. The output is 1 when EITHER OR BOTH inputs are 1. The
output is only 0 when both inputs are 0.
Think of it as: you OR your friend has a ticket (only one of you needs one).
A B X = A OR B
0 0 0
0 1 1
1 0 1
1 1 1
Logic expression: X = A OR B
Alternative notation: X = A+B (a plus between A and B means OR)
10.5 The NAND Gate
The NAND gate has TWO inputs and ONE output. It produces the OPPOSITE result to AND. The output is 0
ONLY when BOTH inputs are 1. Otherwise, the output is 1.
A NAND gate is equivalent to: AND followed by NOT.
A B X = A NAND B
0 0 1
0 1 1
1 0 1
1 1 0
Logic expression: X = A NAND B
Notice: the truth table outputs are exactly the opposite of the AND truth table.
10.6 The NOR Gate
The NOR gate has TWO inputs and ONE output. It produces the OPPOSITE result to OR. The output is 1
ONLY when BOTH inputs are 0.
A NOR gate is equivalent to: OR followed by NOT.
A B X = A NOR B
0 0 1
0 1 0
1 0 0
1 1 0
Logic expression: X = A NOR B
Notice: the truth table outputs are exactly the opposite of the OR truth table.
10.7 The XOR Gate (Exclusive OR)
The XOR gate has TWO inputs and ONE output. The output is 1 ONLY when the inputs are DIFFERENT
(exactly one input is 1). When both inputs are the same (both 0 or both 1), the output is 0.
This is like OR but with the case where both inputs are 1 changed to 0.
A B X = A XOR B
0 0 0
0 1 1
1 0 1
1 1 0
Logic expression: X = A XOR B
Alternative notation: X = A⊕B (a plus in a circle between A and B)
Summary of All Logic Gates
Gate Number of Output is 1 when... Output is 0 when...
Inputs
NOT 1 Input is 0 Input is 1
AND 2 BOTH inputs are 1 Either input (or both) is 0
OR 2 At least ONE input is 1 BOTH inputs are 0
NAND 2 At least ONE input is 0 BOTH inputs are 1
NOR 2 BOTH inputs are 0 At least ONE input is 1
XOR 2 Inputs are DIFFERENT (exactly one Inputs are the SAME (both 0 or both
is 1) 1)
10.8 Logic Circuits and Combined Truth Tables
A logic circuit connects multiple logic gates together. The output of one gate can become the input to another
gate. To analyse a circuit, you complete a truth table for all possible input combinations.
Number of rows in a truth table:
2 inputs = 2² = 4 rows. 3 inputs = 2³ = 8 rows.
The rows follow binary counting order: for 3 inputs (A, B, C): 000, 001, 010, 011, 100, 101, 110, 111.
Method for completing a truth table for a circuit:
• Give intermediate wire connections labels (e.g. D, E).
• Add extra columns to the truth table for each intermediate signal.
• Work left to right (from inputs to output), filling in each column.
• For each column, apply the rule of the relevant gate using the values in the input columns for that gate
only.
Worked Example: Circuit with OR gate (A,B → D), NOT gate (C → E), AND gate (D,E → Y)
A B C D = A OR B E = NOT C Y = D AND E
0 0 0 0 1 0
0 0 1 0 0 0
0 1 0 1 1 1
0 1 1 1 0 0
1 0 0 1 1 1
1 0 1 1 0 0
1 1 0 1 1 1
1 1 1 1 0 0
10.9 Writing Logic Expressions
A logic expression represents the entire circuit as a mathematical formula. To write a logic expression for a
circuit, start with the final output gate and work backwards (or build up from left to right).
Method (working backwards from output):
• Identify the final gate (the one that produces the output).
• Write: OutputLabel = [final gate operation]
• Replace each input to the final gate with its own expression (in brackets).
• Continue replacing until all inputs are the original input variables.
Worked Example 1 — simple circuit:
Circuit: OR gate (inputs A, B → output D), NOT gate (input C → output E), AND gate (inputs D, E → output Y)
Step 1: Final gate is AND. Y = D AND E
Step 2: Replace D with (A OR B). Y = (A OR B) AND E
Step 3: Replace E with (NOT C). Y = (A OR B) AND (NOT C)
Worked Example 2 — larger circuit:
Circuit: NAND gate (P,Q → D), NOT gate (Q → E), XOR gate (D,E → F), AND gate (F,R → Z)
Step 1: Z = F AND R
Step 2: Z = (F) AND R → Z = (D XOR E) AND R
Step 3: Z = ((P NAND Q) XOR E) AND R → Z = ((P NAND Q) XOR (NOT Q)) AND R
10.10 Deriving Circuits and Expressions from Truth Tables
Given a truth table, you need to determine which combination of gates produces it.
Method:
• First, check whether the output column matches any single gate's truth table. If it does, you're done.
• If it doesn't match any single gate, look at the rows where the output is 1.
• For each row where output = 1, identify what combination of inputs and NOT gates would make an
AND gate output 1 (both inputs to AND must be 1).
• Connect these AND expressions with OR if more than one row gives output 1.
Worked Example:
Truth table: A=0,B=0 → X=0 | A=0,B=1 → X=1 | A=1,B=0 → X=0 | A=1,B=1 → X=0
Output is 1 only when A=0 and B=1.
For an AND gate to output 1: both inputs must be 1. Since A=0, we need NOT A. Since B=1, B is already 1.
Therefore: X = (NOT A) AND B
The logic circuit needs: a NOT gate on input A, then feed NOT A and B into an AND gate.