HookThe rounding error that missed a missile
At 20:35 on 25 February 1991, during the Gulf War, an American Patriot missile battery at Dhahran failed to intercept an incoming Scud, which struck a barracks and killed 28 soldiers. The battery's software had done nothing dramatic. It counted time in tenths of a second and multiplied by 0.1 to get seconds — but 0.1 has no exact binary representation. In binary it is the recurring fraction 0.00011001100110011..., and the system stored only a fixed number of bits of it, so each tenth of a second introduced a tiny rounding error. After the battery had been running for around 100 hours the accumulated drift reached about a third of a second, and at a Scud's speed a third of a second is over half a kilometre. The interceptor looked in the wrong patch of sky.
That single incident is the whole of data representation in miniature: every real quantity has to be squeezed into a finite pattern of bits, and the gap between the true value and the stored pattern — its rounding error, its precision, its range — has consequences. This section is where you learn exactly how numbers, characters, images and sound become bit patterns, what is lost in the translation, and how to perform the conversions by hand under exam conditions, where a single mis-carried bit is the difference between full marks and none. Get the encodings exact and you will never write the software that looks in the wrong patch of sky.
ModelWhat counts as a number
Before any encoding, the exam wants the mathematical categories of number. Natural numbers (the set ℕ) are the counting numbers 0, 1, 2, 3 and upward. Integers (ℤ) add the negatives: ..., −2, −1, 0, 1, 2. Rational numbers (ℚ) are any number that can be written as one integer over another, a/b — which includes every terminating or recurring decimal, such as 0.75 (which is 3/4) or 0.333... (which is 1/3). Irrational numbers cannot be written as such a fraction; their decimal expansion never terminates and never repeats — π and the square root of 2 are the standard examples. Real numbers (ℝ) are the rationals and irrationals together: the whole continuous number line.
Two further distinctions carry marks. Ordinal numbers describe position rather than quantity — 1st, 2nd, 3rd — as opposed to the cardinal use of a number that counts how many. And counting versus measurement: counting is discrete and exact (there are 23 students in the room), whereas measurement is continuous and always approximate to the precision of the instrument (a length recorded as 1.7 m really lies somewhere in a band around 1.7). Computers count exactly but can only ever store a measurement to finite precision — which is the deeper root of the Patriot failure.
ModelBases, bits and units
A number base is how many distinct digits a system uses and what each column is worth. Decimal (base 10) columns are powers of ten; binary (base 2) columns are powers of two; hexadecimal (base 16) uses sixteen digits, 0 to 9 then A to F, with A = 10 up to F = 15. Hex earns its place because one hex digit maps exactly onto four binary digits, so it is a human-readable shorthand for long bit patterns. A bit is a single binary digit; a group of eight bits is a byte, and four bits is a nibble — conveniently one hex digit.
Units come in two families the exam expects you to separate. The decimal SI prefixes are powers of ten: 1 kilobyte (kB) = 1,000 bytes, 1 megabyte = 1,000,000, then giga and tera. The binary prefixes are powers of two: 1 kibibyte (KiB) = 1,024 bytes, 1 mebibyte (MiB) = 1,048,576, then gibi and tebi. Manufacturers advertise capacity in decimal units, which is why a drive sold as 1 TB shows up as roughly 931 GiB in an operating system that measures in binary units — the same bytes, two different rulers.
Convert the hexadecimal byte B5 to binary and to decimal. Split it into its two hex digits: B = 11 = 1011 in binary, and 5 = 0101, so B5 is 1011 0101. To find the decimal value, add the place values of the set bits in 10110101: 128 + 32 + 16 + 4 + 1 = 181. Now check it by the hex columns instead: B5 = (11 × 16) + (5 × 1) = 176 + 5 = 181. Both routes give 181, which is the whole point of hexadecimal — four bits to a digit means you can move between the bases in either direction quickly, without writing out the full eight-column binary sum unless you want the cross-check.
ModelUnsigned binary, arithmetic and two's complement
Unsigned binary represents only non-negative whole numbers: an 8-bit unsigned byte holds 0 to 255, because the columns are 128, 64, 32, 16, 8, 4, 2, 1 and the largest pattern, 11111111, sums to 255. Unsigned binary arithmetic follows the same carry rules as decimal addition, except you carry when a column reaches 2 rather than 10.
To store negatives, the A-level uses two's complement. The most significant bit is given a negative weight: in 8 bits it is worth −128, so the representable range shifts to −128 up to +127. To negate a number you invert every bit and add 1. The elegance of the scheme is that subtraction becomes addition: to compute a − b you add a to the two's-complement negative of b and simply discard any carry out of the top column, which means a processor needs only an adder circuit, not separate subtraction hardware.
First an unsigned addition: 0011 1010 (which is 58) + 0001 0110 (which is 22). Adding column by column with carries gives 0101 0000, and 0101 0000 is 64 + 16 = 80, matching 58 + 22 = 80.
Now a subtraction done by two's complement: compute 30 − 20 in 8 bits. 20 is 0001 0100; invert it to 1110 1011 and add 1 to get 1110 1100, which represents −20. Add that to 30 = 0001 1110: 0001 1110 + 1110 1100 = 1 0000 1010. Discard the carry out of the eighth column and you are left with 0000 1010 = 10, and 30 − 20 = 10 is correct. As a check on the negative, 1110 1100 evaluates to −128 + 64 + 32 + 8 + 4 = −20, exactly as intended.
ModelFractions, floating point and where accuracy leaks
Binary columns continue past the point into halves, quarters and eighths, so fixed-point binary can hold fractions: 0110.1100 is 4 + 2 + 0.5 + 0.25 = 6.75. Fixed point wastes bits when the numbers a program handles vary enormously in size, so real systems use floating point, storing a value as a mantissa (the significant digits) and an exponent (where the binary point sits), both usually in two's complement. Normalisation maximises precision by shifting the mantissa so its first two bits differ — 0.1... for a positive value, 1.0... for a negative one — which spends every available bit on significant figures and gives each value a single unique representation.
For a fixed total number of bits there is a permanent trade-off, and it is heavily examined. Give more bits to the exponent and you widen the range of magnitudes you can store but coarsen the precision; give more bits to the mantissa and you gain precision over a narrower range. A result too large for the exponent is an overflow; a result too small, too close to zero, is an underflow. Any value that does not land exactly on a representable pattern is stored as the nearest one, producing a rounding error — reported as an absolute error (the raw difference between true and stored) or a relative error (that difference as a fraction of the true value, which is what actually matters when values span many orders of magnitude).
Normalise the decimal number 12 into an 8-bit two's-complement mantissa with a 4-bit two's-complement exponent, taking the binary point to sit immediately after the first bit of the mantissa. In binary 12 is 1100, which is 0.1100 × 2⁴. So the mantissa is 0.1100000, written as the eight bits 01100000, and the exponent is 4 = 0100. The stored pattern is mantissa 01100000, exponent 0100, and it reads back as +0.75 × 2⁴ = 12. It is normalised because the mantissa begins 01 — a leading 0 followed by a 1 — so no bit is wasted on redundant leading zeros. The relative error here is zero because 12 fits exactly. Try to store 0.1 in the same format and it never can, which is precisely the crack the Patriot battery fell through.
ModelCharacters, and catching corruption
Text is stored by mapping each character to a number. ASCII uses 7 bits, giving 128 codes — enough for the English alphabet, digits and punctuation; the letter A is 65 and a is 97. A crucial subtlety is the character form of a decimal digit: the character '5' is not the integer 5. Its ASCII code is 53, because the digit characters '0' to '9' occupy codes 48 to 57 — which is why converting a digit character to its numeric value means subtracting 48. Unicode exists because 128 codes cannot hold the world's writing systems; it assigns a code point to every character in every script, encoded through schemes such as UTF-8, and its first 128 code points are deliberately identical to ASCII for backward compatibility.
Bits get corrupted in transmission and storage, so data carries redundancy for error checking and correction. A parity bit is set so the total number of 1s is even (even parity) or odd; a receiver that counts the wrong parity knows an odd number of bits flipped. A checksum sends a value calculated from the data so the receiver can recompute and compare. A check digit, as on ISBNs and barcodes, appends a digit derived from the others to catch typing and scanning errors. And majority voting sends each bit several times and takes the most common value, so it can actually correct a single flip rather than merely detect it.
Add an even parity bit to the seven data bits 1010110. Count the 1s: there are four, which is already even, so the parity bit is 0 and the transmitted byte is 01010110. Now suppose one bit flips in transit and the receiver reads 01011110 — that has five 1s, an odd count, and because even parity was agreed the receiver knows the byte is corrupt and asks for a resend. The limit is just as examinable: if two bits had flipped, the count would return to even and the error would slip through undetected. Parity therefore detects an odd number of errors but cannot locate which bit is wrong and cannot catch an even number of flips — which is exactly why safety-critical links use stronger schemes such as majority voting or checksums.
ModelImages, sound and the analogue world
A pattern of bits means nothing until something decides how to read it — the same byte is an integer, a character or a shade of grey depending only on context. The physical world is analogue, varying continuously, whereas computers are digital, storing discrete values, so an analogue-to-digital converter samples the signal at intervals and records the nearest available value. Bitmapped graphics store an image as a grid of pixels, each holding a colour; the resolution is the pixel dimensions and the colour depth is the number of bits per pixel, so the file size is width × height × colour depth. Bitmaps suit photographs but blur when scaled up beyond their resolution. Vector graphics instead store a list of objects — lines, circles, fills — as geometric definitions, so they scale to any size without loss and stay tiny for line art; the practical rule for vector versus bitmap is photographs and detailed images use bitmaps, while logos, maps and diagrams use vectors.
Sound is digitised the same way. The sample rate is how many times per second the amplitude is measured (44,100 Hz for CD audio) and the bit depth is the bits recorded per sample, so file size is sample rate × bit depth × duration × number of channels. MIDI takes a completely different approach: instead of sampling sound it stores instructions — note-on, note-off, pitch, velocity, instrument — like a score the synthesiser performs. That makes MIDI files tiny and fully editable note by note, but incapable of capturing a real singing voice, because there is no recorded waveform, only directions.
Two file-size calculations examiners return to again and again. A bitmap 100 pixels wide by 100 tall at a colour depth of 24 bits needs 100 × 100 × 24 = 240,000 bits, which is 240,000 ÷ 8 = 30,000 bytes, or about 29.3 KiB. A 10-second mono sound clip sampled at 44,100 Hz with a 16-bit depth needs 44,100 × 16 × 10 = 7,056,000 bits, which is 882,000 bytes, or about 861 KiB — and doubling either the sample rate or the bit depth doubles the file, the quality-versus-size trade-off in a single line. Always convert bits to bytes by dividing by 8, and bytes to KiB by dividing by 1,024, and show each step, because the method carries the marks even if your final rounded figure slips a little.
CaseShrinking data and locking it
Data compression shrinks files to save storage space and transmission time, and it splits into two kinds. Lossless compression reconstructs the original exactly: run-length encoding replaces a run of the same value with a count and the value, and dictionary compression replaces frequently occurring sequences with short codes that index a dictionary rebuilt on decompression. Lossy compression, used by JPEG and MP3, permanently discards detail the eye or ear is least likely to notice, achieving far smaller files at the cost of an original that can never be fully recovered.
Encryption scrambles data so that only a key-holder can read it. The Caesar cipher shifts every letter a fixed number of places along the alphabet and is trivially broken, either by trying the 25 possible shifts or by frequency analysis of letters. The Vernam cipher — a one-time pad — is the opposite extreme: it combines the message with a truly random key that is at least as long as the message and used only once, and it is the only cipher with perfect secrecy, provably unbreakable because every possible plaintext is equally consistent with the ciphertext. Everything else in everyday use offers only computational security: breakable in principle, but requiring more computing time than any realistic attacker can bring to bear.
Run-length encoding of the pixel run WWWWWWBBB (nine characters) becomes 6W3B (four characters) — a count paired with each value. It only helps when the data contains long runs; applied to the alternating run WBWBWB it would actually expand the file, which is why RLE suits simple graphics and icons rather than photographs.
The Vernam combine step is a bitwise XOR. Encrypt the character A (ASCII 0100 0001) with a random key byte 0110 1010: XOR each column, writing 1 wherever the two bits differ, to get the ciphertext 0010 1011. To decrypt, XOR the ciphertext with the same key — 0010 1011 XOR 0110 1010 — and every column flips back to 0100 0001, the original A. XOR is self-inverting, which is exactly why a single shared key both locks and unlocks the message.
VocabularyKey terms the mark scheme pays for
TrapsMisconceptions that cost marks
ExamWhat examiners want
Data representation is assessed on the written Paper 2 (7517/2), and it is the most quantitative section on the course, so method marks dominate. For every conversion — hex to binary, binary to decimal, two's-complement negation, floating-point normalisation, a file-size sum — show the working, because a mark scheme awards the steps even when the final figure is wrong. Label your columns (128, 64, 32, 16, 8, 4, 2, 1) so a marker can follow the place values, quote the range of an n-bit representation from the rule (an 8-bit two's-complement byte is −128 to +127), and always convert bits to bytes by dividing by 8 as an explicit line rather than in your head.
Match the answer to the assessment objective. AO1 questions ('state', 'define') want the exact term — the difference between a rational and an irrational number, or a lossy and a lossless codec — so give it precisely. AO2 questions ('convert', 'calculate', 'normalise') are won line by line, and the classic dropped mark is forgetting the interpretation step: after a two's-complement addition, state that the carry is discarded and what the result means. AO3 questions ('justify', 'compare', 'evaluate') want a reasoned choice backed by a trade-off — a vector format for a scalable logo, a higher sample rate for fidelity at the cost of file size, the Vernam cipher for perfect secrecy but with the burden of distributing a one-time key. On any accuracy question, distinguish absolute from relative error and name overflow or underflow explicitly, because those precise terms are what the mark scheme is scanning for.