EuraStudy
Inside a computer everything - numbers, text, images, sound - is ultimately a pattern of bits, and this chapter shows exactly how. It develops the number bases and binary arithmetic, signed integers in two's complement, fixed- and floating-point reals, character sets, bitwise operations, the representation of images and sound, and finally data compression and encryption. It is the most calculation-heavy topic in the A-Level, and every value must be computed exactly.
6 sections~22 min reading time3 competenciesLevel Foundation 1 · Standard 3 · Advanced 2
basic level
AS-Level expects base conversions, unsigned binary arithmetic, ASCII/Unicode, and basic image and sound representation.
higher level
The full A-Level adds two's-complement signed arithmetic, fixed- and floating-point representation with normalisation and error, bitwise masks, and compression (RLE and Huffman) and encryption (Caesar, Vernam, and public-key principles).
Reading depth: In depth
Text size: Standard
Denary, binary and hexadecimal reference
Denary to binary to hex
Sum the place values that make 203, group the bits into two nibbles, and translate each to a hex digit.
Convert the denary number 203 to 8-bit binary and then to hexadecimal.
; ; 32 and 16 do not fit; ; 4 does not fit; ; . So the 128, 64, 8, 2 and 1 columns are set.
Columns 128 64 32 16 8 4 2 1 give 1 1 0 0 1 0 1 1, i.e. .
: and .
Result: . Checking: .
Typical mistakes
Active revision
Convert denary 203 to binary and to hexadecimal, and convert hexadecimal 2F to binary and to denary, showing your working.
Active recall
Recall the key points — then reveal.
Sources: GCE AS and A level subject content for computer science (Department for Education) · AQA A-level Computer Science 7517 specification (AQA)
The range of an 8-bit two's-complement integer
Two's-complement range
For this is to : the leading bit's place value is , giving one extra negative value.
Compute using 8-bit two's-complement arithmetic by negating 20 and adding.
and .
Invert to , then add 1 to get .
. Discard the carry out of the top bit.
Result: The 8-bit result is , and . The carry out of the leading bit is discarded, not overflow, because the sign of the result is correct.
Typical mistakes
Active revision
Represent as an 8-bit two's-complement number, then compute in 8-bit two's complement by adding the complement, showing the carry, and state the range of an 8-bit signed integer.
Active recall
Recall the key points — then reveal.
Sources: AQA A-level Computer Science 7517 specification (AQA)
A floating-point number's fields
Floating-point value
The mantissa holds the significant digits and the exponent scales them - the binary equivalent of standard form.
Relative rounding error
The absolute error expressed as a fraction of the true value; it accumulates through long calculations.
Represent 5.5 in denary as a normalised floating-point number with an 8-bit two's-complement mantissa (binary point after the first bit) and a 4-bit two's-complement exponent.
(that is ).
Move the binary point to just after the leading 0 sign bit: (the point moved 3 places right of its normalised position, so the exponent is 3).
Mantissa (sign 0, then ) = ; exponent in 4-bit two's complement.
Result: 5.5 is stored as mantissa , exponent . Check: mantissa , and .
Typical mistakes
Active revision
Normalise the denary number 5.5 into an 8-bit two's-complement mantissa (binary point after the first bit) and a 4-bit two's-complement exponent, and verify your representation converts back to 5.5.
Active recall
Recall the key points — then reveal.
Sources: AQA A-level Computer Science 7517 specification (AQA)
Digit character to value
Because '0' = 48, '1' = 49, ..., subtracting 48 from a digit's code gives its numeric value.
Compute , and separately shift left by one place. Interpret both results.
AND gives 1 only where both bits are 1. The high nibble is masked to 0 (AND 0000) and the low nibble is preserved (AND 1111): .
The mask has extracted the low four bits, , discarding the high nibble - the standard way to read a nibble out of a byte.
shifted left by one is : becomes .
Result: The mask yields (the low nibble, 5); the left shift doubles the value from 22 to 44. Masks select bits; shifts multiply or divide by powers of two.
Typical mistakes
Active revision
Given ASCII 'A' = 65, state the code for 'F' and for 'a'. Then compute and state what the mask has done, and give the result of shifting left by one place and its denary meaning.
Active recall
Recall the key points — then reveal.
Sources: GCE AS and A level subject content for computer science (Department for Education)
Sampling an analogue sound wave
Bitmap file size
Colour depth gives possible colours per pixel; divide the bit total by 8 for bytes.
Sound file size
Higher rate or resolution improves fidelity but increases size proportionally; stereo (2 channels) doubles mono.
An uncompressed bitmap is 64 pixels wide, 48 pixels high, with a colour depth of 4 bits per pixel. Find its size in bits, bytes and kibibytes.
bits.
Divide by 8: bytes.
Divide by 1024: KiB.
Result: The image is 12 288 bits = 1536 bytes = 1.5 KiB. A colour depth of 4 bits allows colours per pixel.
Typical mistakes
Active revision
A bitmap is 64 pixels wide, 48 high, with a colour depth of 4 bits. Calculate its size in bits, bytes and kibibytes. Then find the size in megabytes of a 30-second mono sound sampled at 44 100 Hz with 16-bit resolution.
Active recall
Recall the key points — then reveal.
Sources: AQA A-level Computer Science 7517 specification (AQA)
A Huffman coding tree
Caesar cipher
Each plaintext letter's position is shifted by the key and wrapped round the 26-letter alphabet.
Using the Huffman tree with A:5, B:2, C:1, D:1 (left edge = 0, right edge = 1), give the code for each symbol and encode the string 'BAD'.
A is the left child of the root: 0. B is right-then-left: 10. C is right-right-left: 110. D is right-right-right: 111.
B = 10, A = 0, D = 111, so 'BAD' = 10 0 111 = 100111.
No code is a prefix of another (prefix-free), so reading 100111 left to right: 10 (B), 0 (A), 111 (D) is the only possible split.
Result: Codes A = 0, B = 10, C = 110, D = 111; 'BAD' encodes to 100111 (6 bits, versus 6 bits for 2-bit fixed codes here, with the saving growing as the frequent A recurs).
Typical mistakes
Active revision
Build a Huffman tree for the symbols with frequencies E:8, A:5, T:3, N:2 (combining the two lowest each time), give each symbol's code, and state why the codes can be decoded without ambiguity.
Active recall
Recall the key points — then reveal.
Sources: AQA A-level Computer Science 7517 specification (AQA)
References & sources
Department for Education