Syllabus coverage
- Binary magnitudes, and the difference between binary prefixes and decimal prefixes: kibi and kilo, mebi and mega, gibi and giga, tebi and tera
- The binary, denary and hexadecimal number bases, and Binary Coded Decimal (BCD)
- One's and two's complement representation for binary numbers
- Converting an integer value from one number base or representation to another
- Binary addition and subtraction using positive and negative binary integers, and how overflow can occur
- Practical applications where BCD and hexadecimal are used
- Representing character data in its internal binary form, depending on the character set: ASCII, extended ASCII and Unicode
- How data for a bitmapped image are encoded: pixel, file header, image resolution, screen resolution, colour depth/bit depth
- Calculations to estimate the file size of a bitmap image, and the effects of changing image resolution and colour depth on image quality and file size
- How data for a vector graphic are encoded: drawing object, property, drawing list, and justifying the use of a bitmap or a vector graphic for a task
- How sound is represented and encoded: sampling, sampling rate, sampling resolution, analogue and digital data
- The impact of changing the sampling rate and the sampling resolution, including the impact on file size and accuracy
- The need for compression, and examples of its use; lossy and lossless compression, and justifying a method in a given situation
- How a text file, bitmap image, vector graphic and sound file can be compressed, including run-length encoding (RLE)
Part of the AS & A Level Computer Science syllabus 9618.
Binary magnitudes and the two systems of prefixes
A bit is one binary digit, a nibble is 4 bits and a byte is 8 bits. Everything in this section is about counting those units, and the awkward part is that two systems of prefixes are in use at the same time. Memory is made of cells selected by binary addresses, so the number of locations in a memory chip is always a power of two: 2^10 = 1024, 2^20 = 1 048 576, 2^30 = 1 073 741 824, 2^40 = 1 099 511 627 776. The prefixes that describe these powers of two are the binary prefixes: kibi, mebi, gibi and tebi.
The prefixes you meet in physics, and in advertising, are the decimal prefixes: kilo, mega, giga and tera, which are powers of ten. One kilobyte (kB) is 1000 bytes, but one kibibyte (KiB) is 1024 bytes. One megabyte (MB) is 1 000 000 bytes, but one mebibyte (MiB) is 1 048 576 bytes. The symbols matter as well as the words: the binary prefixes always take the letter i, so KiB, MiB, GiB and TiB are the binary ones and kB, MB, GB and TB are the decimal ones.
The gap between the two systems grows at every step, because you are multiplying by 1024 instead of 1000 each time: the binary unit is about 2.4% larger at kilo, 4.9% at mega, 7.4% at giga and 10.0% at tera. That is why a hard drive sold as 1 TB holds 10^12 bytes, which an operating system working in powers of two reports as about 931 GiB. The manufacturer is not lying and the computer is not broken; they are using different prefixes, and an exam question that asks you to explain the discrepancy wants exactly that sentence.
In an exam, always say which system you are using. RAM, cache sizes and file sizes within an operating system are usually quoted in binary prefixes because they are powers of two; storage device capacities, network speeds and data transfer allowances are usually quoted in decimal prefixes. If a question simply says GB and asks for a number of bytes, use 10^9 and say so; if it says GiB, or asks about a memory chip, use 2^30.
- kibi (Ki) = 2^10 = 1024, against kilo (k) = 10^3 = 1000.
- mebi (Mi) = 2^20 = 1 048 576, against mega (M) = 10^6 = 1 000 000.
- gibi (Gi) = 2^30 = 1 073 741 824, against giga (G) = 10^9 = 1 000 000 000.
- tebi (Ti) = 2^40 = 1 099 511 627 776, against tera (T) = 10^12 = 1 000 000 000 000.
- 1 byte = 8 bits, 1 nibble = 4 bits; a 4 GiB memory module holds 4 x 2^30 bytes.
- The binary prefix always contains an i: KiB is 1024 bytes, kB is 1000 bytes.
| Pair | Decimal value | Binary value | Binary unit is larger by |
|---|---|---|---|
| kilo / kibi (kB / KiB) | 1 000 bytes | 1 024 bytes | 2.4% |
| mega / mebi (MB / MiB) | 1 000 000 bytes | 1 048 576 bytes | 4.9% |
| giga / gibi (GB / GiB) | 1 000 000 000 bytes | 1 073 741 824 bytes | 7.4% |
| tera / tebi (TB / TiB) | 1 000 000 000 000 bytes | 1 099 511 627 776 bytes | 10.0% |
Number bases, conversion, BCD and where each is used
Denary is base 10 and uses the digits 0 to 9. Binary is base 2, using only 0 and 1, which suits a circuit that can be on or off. Hexadecimal is base 16, using 0 to 9 and then A to F for the values 10 to 15. Hexadecimal exists for one reason: 16 = 2^4, so one hex digit holds exactly four bits, one nibble. Converting between binary and hex is therefore grouping, never arithmetic, which is why programmers use it.
To convert binary to denary, add the place values of the 1 bits: 128, 64, 32, 16, 8, 4, 2, 1, so 1100 1010 = 128 + 64 + 8 + 2 = 202. To convert denary to binary, subtract the largest place value that fits, then the next, and so on: 202 - 128 = 74, 74 - 64 = 10, 10 - 8 = 2, 2 - 2 = 0, giving 1100 1010. To convert binary to hex, group the bits into fours starting from the right and convert one group at a time: 1100 -> C and 1010 -> A, so 202 is CA. To convert hex to denary, multiply each digit by its power of 16: 2F = 2 x 16 + 15 = 47.
Binary Coded Decimal (BCD) is not a number base. Each denary digit is stored separately in its own nibble, so 47 is stored as 0100 0111, not as the binary 0010 1111. A byte holds two BCD digits, so it can represent 00 to 99, where the same byte in pure binary can represent 0 to 255. The six codes 1010 to 1111 are never used, and that wasted capacity is the price you pay for the convenience.
BCD is used where the digits themselves matter rather than the number as a whole. A calculator, a digital clock or a digital multimeter has to send one digit at a time to a seven-segment display driver, and those drivers expect a BCD digit; converting pure binary into separate decimal digits for display needs extra time and code. Financial and accounting systems also use BCD-based decimal types, because values such as 0.10 cannot be held exactly in binary and rounding errors are unacceptable in money.
Hexadecimal is used wherever a human has to read or write a binary value. Memory addresses in a debugger or a hex dump, machine code instructions and opcodes, colours in a web page such as #FF8000, MAC addresses, IPv6 addresses, error codes, hash values and Unicode code points are all written in hex. The reason is always the same three points: it is far shorter than binary, each digit maps to exactly four bits so conversion is instant, and there are fewer characters to misread.
| Value in denary | Binary | BCD | Hexadecimal |
|---|---|---|---|
| 9 | 0000 1001 | 0000 1001 | 9 |
| 47 | 0010 1111 | 0100 0111 | 2F |
| 128 | 1000 0000 | 0001 0010 1000 | 80 |
| 202 | 1100 1010 | 0010 0000 0010 | CA |
Negative numbers: one's and two's complement
A fixed number of bits can only hold a fixed range of values, so a decision has to be made about how to represent a negative number. The method used in this syllabus and in real hardware is to give the most significant bit a negative place value. That bit is the sign bit: 0 means the number is positive and 1 means it is negative. The advantage over simply marking a sign is that ordinary binary addition then works for negative numbers with no special cases.
One's complement is formed by inverting every bit: 46 in 8 bits is 0010 1110, so -46 in one's complement is 1101 0001. In 8 bits it covers -127 to +127 and it has two representations of zero, 0000 0000 (+0) and 1111 1111 (-0), which means a test for zero needs two comparisons and arithmetic needs an extra correction step.
Two's complement is formed by inverting every bit and then adding 1, which is the same as subtracting the value from 2^n: 46 is 0010 1110, inverting gives 1101 0001, adding 1 gives 1101 0010, and 256 - 46 = 210 = 1101 0010. In 8 bits two's complement covers -128 to +127 and has only one zero. The range is asymmetric because 1000 0000 is -128 and there is no positive counterpart.
To read a two's complement number back, use -128 as the place value of the sign bit: 1101 0010 is -128 + 64 + 16 + 2 = -46. To change the sign of a number, apply the same invert-and-add-1 operation in either direction, which is why subtraction can be done by addition in hardware. In 16 bits the range is -32 768 to +32 767, so doubling the word length does not simply double the range.
| Value | 8-bit two's complement | Check |
|---|---|---|
| +46 | 0010 1110 | 32 + 8 + 4 + 2 = 46 |
| -46 | 1101 0010 | -128 + 64 + 16 + 2 = -46 |
| +127 | 0111 1111 | Largest positive value |
| -128 | 1000 0000 | Smallest value; it has no positive equivalent |
| -1 | 1111 1111 | -128 + 127 = -1 |
Binary addition, subtraction and overflow
The four rules of binary addition are 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 0 carry 1, and 1 + 1 + 1 = 1 carry 1. Work from the least significant bit upwards and write the carry above the next column. For example 0010 0011 (35) + 0001 1010 (26) = 0011 1101 (61), and in that sum the carry out of the most significant bit is 0, so nothing has been lost.
Subtraction is done by adding the two's complement. To work out A - B, find the two's complement of B and add it to A, then discard any carry out of the most significant bit. For 61 - 26: 26 is 0001 1010, so -26 is 1110 0110, and 0011 1101 + 1110 0110 = 1 0010 0011. The carry out is discarded and the answer is 0010 0011 = 35. The discarded carry is not a mistake - it is the bit that was borrowed to make the negative number in the first place.
Overflow happens when the true result is outside the range that the word length can represent, so the answer wraps round and is wrong. With signed numbers the reliable test is that the carry into the sign bit differs from the carry out of it, which has a simple consequence: adding two positive numbers and getting a negative result, or adding two negative numbers and getting a positive result, means overflow. For example 100 + 100 in 8-bit two's complement is 0110 0100 + 0110 0100 = 1100 1000, which reads as -56, and -100 + -100 is 1001 1100 + 1001 1100 = 1 0011 1000, which reads as +56. Both results are wrong because 200 and -200 are outside -128 to +127.
A carry out of the most significant bit is not the same thing as overflow. Adding -1 and +1 gives 1111 1111 + 0000 0001 = 1 0000 0000: there is a carry out, but the answer 0 is correct and there is no overflow. In unsigned arithmetic, overflow is simply a result that needs more than the available bits, so 255 + 1 = 0 with a carry out. When overflow occurs a program must either test the processor's overflow flag and handle the error, or use a wider word length such as 16 or 32 bits.
| Sum (8-bit two's complement) | Working | Result | Overflow? |
|---|---|---|---|
| 35 + 26 | 0010 0011 + 0001 1010 = 0011 1101 | 61 | No |
| 61 - 26 | 0011 1101 + 1110 0110 = (1) 0010 0011 | 35; carry out discarded | No |
| -1 + 1 | 1111 1111 + 0000 0001 = (1) 0000 0000 | 0; carry out, but correct | No |
| 100 + 100 | 0110 0100 + 0110 0100 = 1100 1000 | Reads as -56, should be 200 | Yes - positive + positive gave a negative |
| -100 + -100 | 1001 1100 + 1001 1100 = (1) 0011 1000 | Reads as +56, should be -200 | Yes - negative + negative gave a positive |
Character data and character sets
A computer stores characters as numbers, so every character set is a published table that maps each character to a unique binary code. The set is agreed in advance so that a file written on one machine can be read on another. The three the syllabus names are ASCII, extended ASCII and Unicode, and the differences between them are all about how many bits are used and whose characters are included.
ASCII uses 7 bits, so it defines 128 characters. Codes 0 to 31 are control codes that tell a device what to do rather than printing a symbol - null, tab, carriage return, line feed, escape - and 127 is delete. Codes 32 to 126 are the printable characters, and the arrangement is deliberate: the digits 0 to 9 are at 48 to 57, capital letters A to Z at 65 to 90, and lower case a to z at 97 to 122, so converting between cases is a single bit change and 32 is the space character. You are not expected to memorise any of these codes, but the pattern explains why sorting text alphabetically works.
Extended ASCII uses 8 bits and so defines 256 characters. The extra 128 codes were used for accented letters, currency symbols, box-drawing characters and mathematical symbols, which made it possible to write most Western European languages. The problem is that no single version was agreed: different manufacturers assigned different characters to the same code, so a file written with one version showed the wrong symbols when opened with another.
Unicode is the answer to that problem. It is a single character set intended to cover every character in every written language, plus symbols and emoji, and it currently defines well over 100 000 characters. Unicode is a set of code points, usually written U+0041, and it is stored using an encoding such as UTF-8, UTF-16 or UTF-32. UTF-8 is variable length: it uses 1 byte for the first 128 code points, which are identical to ASCII, and up to 4 bytes for characters from other scripts, which is why an old ASCII file is still valid UTF-8 and why English text stays compact while Chinese or Arabic text takes more space.
| Character set | Bits per character | Characters defined | Main point |
|---|---|---|---|
| ASCII | 7 | 128 | English letters, digits and punctuation plus 33 control codes; the basis of everything that follows |
| Extended ASCII | 8 | 256 | Adds accented letters and symbols for Western European languages, but the versions disagree with each other |
| Unicode (UTF-8) | 8, 16, 24 or 32 (1 to 4 bytes) | Over 100 000 code points | Covers every script and symbol; the first 128 code points are identical to ASCII |
Bitmap images: encoding, file size and the effect of changing them
A bitmapped image is a rectangular grid of pixels. Each pixel holds one colour, stored as a binary code whose length is the colour depth, also called the bit depth: 1 bit gives 2 colours, 8 bits give 256, 16 bits give 65 536 and 24 bits give 16 777 216, which is enough for photographic work. The image is stored as the pixel values written in order, usually row by row, and a palette or colour table may be used when the depth is small so that each pixel stores an index instead of a full colour.
Before the pixel data comes the file header, which is metadata about the file rather than part of the picture: an identifier that shows the file type, the width and height in pixels, the colour depth, the resolution metadata used for printing, the palette if there is one, the compression method used, and the offset at which the pixel data starts. Without the header the pixel data is just a long stream of bits with no way of knowing where one row ends and the next begins, so no program could draw it. The header is small and is normally ignored in file size estimates.
Image resolution is the number of pixels in the image itself, quoted as width x height, so a 4000 x 3000 image contains 12 million pixels. Screen resolution is the number of pixels the display can show, such as 1920 x 1080. They are different things: an image larger than the screen has to be scrolled or scaled down to fit, and scaling down throws pixels away. For printing, resolution is often quoted in dots per inch, which is why the same image can look sharp on a screen and soft on a poster.
The file size is estimated as width x height x colour depth in bits, divided by 8 to convert to bytes, plus a small allowance for the header. A 4000 x 3000 image at 24 bits is 4000 x 3000 x 24 = 288 000 000 bits, which is 36 000 000 bytes, or 36 MB (34.3 MiB). That single calculation shows why uncompressed photographs are so large and why the prefixes of the first section matter.
Changing the image changes both quality and file size, and the two changes behave differently. Increasing the image resolution captures or stores more detail but increases the number of pixels, so the file grows with the square of the change: double the width and the height and the file is four times as large. Reducing resolution makes the file smaller and loses fine detail, and enlarging an image beyond its own resolution cannot add detail - the software interpolates new pixels, so the result looks blocky and soft. Increasing the colour depth gives more colours, smoother gradients and less banding, and increases the file size in direct proportion, because each pixel simply uses more bits. Reducing the colour depth produces visible bands where a gradient should be, and can turn a photograph into a posterised image.
| Colour depth | Colours available | Bits per pixel | Size of a 1000 x 1000 image |
|---|---|---|---|
| 1 bit | 2 | 1 | 125 kB |
| 8 bits | 256 | 8 | 1 MB |
| 16 bits | 65 536 | 16 | 2 MB |
| 24 bits | 16 777 216 | 24 | 3 MB |
Vector graphics and choosing between bitmap and vector
A vector graphic is not stored as pixels at all. It is stored as a drawing list, an ordered set of instructions for drawing drawing objects such as lines, rectangles, circles, curves and text. Each object has properties that describe it: its type, the coordinates of its position, its size or radius, its fill colour, its line colour and thickness, its rotation, and its transparency or layering. A circle might be recorded as a centre at (120, 80), a radius of 40, a red fill and a black outline two units thick.
When the graphic is displayed or printed, the software reads the drawing list and draws the objects at the resolution of the output device. This has two consequences that examiners look for. First, enlarging a vector graphic does not lose quality, because the shape is recalculated rather than resampled - the same circle is drawn with more pixels, not stretched. Second, the file size depends on the number and complexity of the objects, not on the size at which the graphic is displayed, so the same logo file is equally small on a business card and on a billboard.
The limitation is content. A vector graphic is good at shapes with flat or gradient fills and at text, and poor at anything photographic, because a photograph contains millions of subtly different colours that no list of shapes can describe. Attempting photographic realism in vector produces very large files and still looks artificial. A vector file that includes a photograph therefore embeds a bitmap inside the drawing list, which is why some logos contain a raster element.
The choice for a given task is decided by the content and the use, not by habit. If the picture is made of shapes and has to be scaled to different sizes, use a vector. If the picture is a photograph, a scan, a screenshot or anything with continuous tone, use a bitmap, and accept that it has one fixed resolution.
| Task | Better choice | Why |
|---|---|---|
| Company logo used on a van, a website and a poster | Vector | Made of shapes and text, and must stay sharp at every size; one small file serves all uses |
| Photograph of a product for an online shop | Bitmap | Continuous tone with millions of colours, which only a pixel grid can capture |
| Scanned handwritten order form | Bitmap | The scanner produces pixels; the value is in the exact appearance of the paper |
| Engineering drawing or circuit diagram | Vector | Precise geometric shapes, clean lines at any zoom, and small file size |
| Icon set for an app, drawn at several sizes | Vector | Simple shapes that must render cleanly at 16 pixels and at 512 pixels |
| Screenshot of a program window | Bitmap | Captured as pixels and contains text and shading that cannot be rebuilt as shapes |
Sound: sampling, encoding and file size
A sound is a pressure wave, and a microphone converts it into a voltage that changes continuously. That is analogue data: the value exists at every instant and can take any value in a range. A computer can only store numbers, so the wave must be converted into digital data by an analogue-to-digital converter, which does two things: it measures the wave at regular intervals, and it rounds each measurement to the nearest available binary value.
Sampling is the taking of those measurements. The sampling rate is how many samples are taken per second, measured in hertz: a CD uses 44 100 samples per second. The sampling resolution, also called the bit depth, is the number of bits used for each sample, so 16-bit sampling gives 65 536 possible amplitude levels. Rounding each sample to the nearest level is called quantisation, and the small error it introduces is heard as low-level noise.
The file size follows from those two numbers: sampling rate x sampling resolution x duration in seconds x number of channels, divided by 8. A three-minute stereo track at 44 100 Hz and 16 bits is 44 100 x 16 x 180 x 2 = 254 016 000 bits, or 31 752 000 bytes, about 31.8 MB. Compare that with a bitmap; the same arithmetic applies, and again the division by 8 catches people out.
Changing either setting has a predictable effect. Raising the sampling rate records the wave more often, so rapid changes are captured and higher frequencies are preserved, and the file size rises in direct proportion. Lowering it loses the fast changes: high frequencies disappear, and a rate that is too low for the sound being recorded misrepresents the wave altogether. Raising the sampling resolution gives more amplitude levels, so each sample is closer to the true value, the quantisation noise falls and the dynamic range improves, and again the file size rises in proportion. Lowering it produces audible hiss and a flattened, distorted sound. Typical settings are 44 100 Hz at 16 bits for music, and 8 000 Hz for speech in a telephone system, where the range of frequencies needed is much smaller.
| Sampling rate | Sampling resolution | Channels | File size for 60 seconds |
|---|---|---|---|
| 8 000 Hz | 8 bits | 1 (mono) | 480 000 bytes |
| 22 050 Hz | 16 bits | 1 (mono) | 2 646 000 bytes |
| 44 100 Hz | 16 bits | 1 (mono) | 5 292 000 bytes |
| 44 100 Hz | 16 bits | 2 (stereo) | 10 584 000 bytes |
Compression: lossy, lossless and the methods used for each file type
Compression reduces the number of bits needed to store or transmit the same content, and the reasons are practical: storage costs money, a network has limited bandwidth, and a smaller file uploads, downloads, streams and backs up faster. A web page of uncompressed 24-bit photographs would take seconds to load on a slow connection, and a music library of uncompressed audio would fill a phone several times over.
Lossless compression reduces the file and lets the original be reconstructed exactly. It works by finding and removing redundancy - repeated patterns, unused space in the encoding, predictable sequences. Lossy compression reduces the file much further by permanently discarding data that is judged to matter least, usually because a human eye or ear will not notice its absence. The discarded data can never be recovered, and repeated lossy compression of the same file makes the loss worse each time.
Run-length encoding (RLE) is the simplest lossless method. A run of identical values is replaced by a count and the value: a row of pixels of 12 white, then 3 black, then 5 white is stored as 12W 3B 5W instead of twenty separate values. RLE works extremely well on images with large areas of one colour - icons, logos and scanned line drawings - and on fax pages, which are mostly long runs of white. It works badly on photographs, where neighbouring pixels almost never share a value for long, because every short run still needs a count, and the file can end up larger than the original.
Different file types are compressed in different ways. A text file is compressed losslessly, usually by a dictionary method that replaces frequently repeated words and sequences with short codes, as ZIP and GZIP do; lossy compression of text is never acceptable because every character carries meaning. A bitmap image can be compressed with RLE where there are flat areas of colour, with a lossless format such as PNG for graphics and screenshots, or with a lossy format such as JPEG for photographs, which discards fine colour detail and high-frequency information that the eye is unlikely to notice. A vector graphic is already a compact list of objects, so it is compressed by removing unused or redundant properties, rounding long coordinate values, merging repeated objects and then applying a general lossless method such as the DEFLATE compression used inside an SVG file; the savings are real but smaller than for a bitmap, because there was less redundancy to remove. A sound file can be compressed losslessly with a format such as FLAC, which typically halves the size by predicting each sample from the ones before it, or lossily with MP3 or AAC, which use a model of human hearing to discard quiet sounds that would be masked by louder ones at the same moment.
| File type | Lossless method | Lossy method | When each is appropriate |
|---|---|---|---|
| Text | Dictionary-based coding of repeated words and sequences (ZIP, GZIP) | None - not acceptable | Always lossless: a changed character changes the meaning, and program code and data must survive exactly |
| Bitmap image | RLE for flat colour; PNG for graphics and screenshots | JPEG for photographs | Lossless for screenshots, icons and line art; lossy for photographs on a web page where small size matters |
| Vector graphic | Removing redundant properties, rounding coordinates, then DEFLATE on the SVG | Rarely used; lower coordinate precision only | Already compact, so compression gains are modest and it should stay lossless for editing |
| Sound file | FLAC, predictive coding | MP3 and AAC, using a model of hearing | Lossless for masters and archives; lossy for streaming and portable players |
Key terms you must be able to define
- Binary prefix
- A prefix that describes a power of two, used for memory and file sizes: kibi (Ki) = 2^10 = 1024, mebi (Mi) = 2^20, gibi (Gi) = 2^30, tebi (Ti) = 2^40, always written with an i as in KiB. It is larger than the matching decimal prefix - kilo 10^3, mega 10^6, giga 10^9, tera 10^12 - and the gap grows from 2.4% at kilo to 10.0% at tera.
- Binary Coded Decimal (BCD)
- A representation in which each denary digit is stored separately in its own nibble, so 47 is 0100 0111. Only the codes 0000 to 1001 are used. It is used where digits are displayed or handled one at a time, as in calculators, digital clocks and financial systems.
- One's complement
- A representation of negative binary numbers formed by inverting every bit of the positive value. In 8 bits it covers -127 to +127 and has two representations of zero, +0 (0000 0000) and -0 (1111 1111).
- Two's complement
- A representation of negative binary numbers formed by inverting every bit and adding 1, which is the same as subtracting the value from 2^n. In 8 bits it covers -128 to +127, has a single zero, and allows subtraction to be carried out as addition.
- Overflow
- The condition in which the true result of a calculation is outside the range that the word length can represent, so the bits produced give a wrong value. With signed numbers it is detected when the carry into the sign bit differs from the carry out of it, for example when adding two positives gives a negative result.
- Image resolution
- The number of pixels in the image itself, quoted as width x height, for example 4000 x 3000. It is not the same as screen resolution, which is the number of pixels the display can show.
- Colour depth (bit depth)
- The number of bits used to store the colour of each pixel. 1 bit gives 2 colours, 8 bits give 256, 24 bits give 16 777 216. Increasing it increases file size in direct proportion and reduces banding.
- File header
- The block of metadata at the start of an image file, holding the file type identifier, the width and height in pixels, the colour depth, the resolution metadata, any palette, the compression method used and the offset of the pixel data. Without it the pixel data cannot be interpreted.
- Drawing list
- The stored form of a vector graphic: an ordered list of drawing objects, each with properties such as type, position, size, fill colour and line thickness, which is redrawn at the resolution of the output device.
- Sampling rate
- The number of samples of an analogue signal taken per second, measured in hertz. Raising it captures higher frequencies more accurately and increases the file size in direct proportion.
- Sampling resolution
- The number of bits used to store each sample, giving 2^n amplitude levels. Raising it reduces the quantisation error and the resulting noise, and increases the file size in direct proportion.
- Lossless compression
- Compression that allows the original data to be reconstructed exactly, by removing redundancy. Used for text, program files, archives and audio masters; examples are ZIP, PNG, FLAC and run-length encoding.
- Lossy compression
- Compression that permanently discards data judged least noticeable to a human, giving a much smaller file that cannot be restored to the original. Examples are JPEG for images and MP3 or AAC for sound.
- Run-length encoding (RLE)
- A lossless method that replaces each run of identical values with a count and the value, such as 12W 3B 5W. It is effective on images with large areas of one colour, such as icons, line drawings and fax pages, and can enlarge a photograph because neighbouring pixels rarely repeat.
Applied to real systems
9618 sets its questions inside systems you already use - a phone, a school network, a supermarket till, a website, a bank. These show how to apply the theory to a context you have not seen before, then you write your own.
Every colour in a web page is written as six hexadecimal digits, two for each of red, green and blue. The code #FF8000 means 255 red, 128 green and 0 blue, which is an orange. This is a good illustration of why hex is used: the six digits are compact, each pair maps directly onto a byte, and the 24-bit value can be read and adjusted by a designer far more easily than a string of 24 ones and zeros. A single character typed wrongly in binary is almost invisible; in hex it stands out.
Real-time clock chips such as the DS1307, which keep the time in many small embedded systems, store seconds, minutes and hours as BCD bytes rather than as plain binary, so the value for 47 seconds is held as 0100 0111. Digital clocks, calculators and multimeters do the same because each digit is sent straight to a display driver one at a time, and because a decimal value such as a price has to be exact rather than the nearest binary approximation. The waste of six unused codes per digit is accepted in exchange for that convenience.
A single web page can now mix English, Greek, Arabic, Chinese and emoji without any special handling, because Unicode assigns every one of those characters its own code point and UTF-8 encodes them in one to four bytes. Before Unicode, the same page needed several incompatible extended ASCII versions, and text written in one appeared as nonsense when opened in another. UTF-8 also keeps English text compact, because its first 128 code points are the ASCII characters unchanged, which is why plain ASCII files still open correctly today.
A fax machine scans a page line by line, and most lines on a typical business letter are almost entirely white with a short block of black text. Encoding every run of identical pixels as a count and a value removes almost all of that repetition, so a page that would take megabytes as an uncompressed bitmap is sent down a telephone line in a fraction of the time. It also shows the limitation: a fax of a photograph, where the tone changes constantly, compresses far less well, because there are hardly any long runs to encode.
A music track distributed as MP3 is compressed lossily, using a model of human hearing to discard quiet sounds that would be masked by louder ones at the same instant, and the file is typically a tenth of the uncompressed size. The same recording stored as FLAC is compressed losslessly, at roughly half the uncompressed size, and decodes back to exactly the original samples. A studio therefore keeps the master in a lossless format and distributes a lossy copy, because editing and re-encoding the lossy version repeatedly would accumulate audible damage.
Flashcards
Click a card to flip it. Mark honestly — the tracker uses this.
Exam-style questions
8 questions, 30 marks. Write your answer, then reveal the mark scheme and tick each point you actually made. Answering honestly here is what makes the rest of the site useful.
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
Exam technique for this topic
- Quote the unit and the prefix system in every answer that involves a size. One mark is regularly lost by writing '1024' where the question said kilobyte, or by leaving a file size as a number of bits when the question asked for bytes, MB or MiB.
- In any complement or arithmetic question, state the word length first and then show every step: write the positive value, invert, add 1, add, discard the carry. You can check a subtraction by adding the answer back to the number you subtracted, and examiners award method marks even when the final arithmetic slips.
- For file size calculations, do the bit count first and convert at the end. Then check whether the question is about resolution or colour depth, because resolution changes the size by the square and colour depth changes it in direct proportion.
- In a justify question about bitmap against vector, or lossy against lossless, name the use and say what the user needs from the file - sharp edges at any size, exact recovery, small download, print quality - rather than using words such as 'better' or 'higher quality' on their own.
- Use the syllabus vocabulary exactly: pixel, file header, image resolution, screen resolution, colour depth, drawing object, property, drawing list, sampling, sampling rate, sampling resolution, analogue and digital. A correct idea described in vague words often scores nothing.