Cambridge AS & A Level · Part 1 · Chapter 1
Information Representation
How a machine that only knows 0 and 1 stores numbers, text, pictures and sound, and how those files are made smaller. Every figure, task, question and exam question from the chapter is here, with labs that give you fresh numbers every time.
Guru Jazzy🎯 Learning objectives
By the end of this chapter you should be able to:
- show you understand binary magnitudes and the difference between binary prefixes and decimal prefixes
- show you understand the different number systems and work in them
- Do binary addition and subtraction
- describe practical uses of BCD and hexadecimal
- show you understand how character data is held in binary, and that this depends on the character set
- show you understand how a bitmap is encoded, calculate a bitmap's file size, and explain how changing its elements affects quality and size
- show you understand how a vector graphic is encoded, and justify choosing a bitmap or a vector graphic for a task
- show you understand how sound is represented and encoded, and the effect of changing sampling rate and resolution
- explain why compression is needed, with examples; tell lossy from lossless and justify the choice
- describe how text, bitmap, vector and sound files can be compressed
🔟 Denary: the system you already use
Ordinary numbers are written in denary, a base-10 system. Ten symbols (0 to 9) are enough, because each position in a number has a place value ten times the one to its right. For 346:
| Place value | 10² = 100 | 10¹ = 10 | 10⁰ = 1 |
|---|---|---|---|
| Digit | 3 | 4 | 6 |
| Worth | 3 × 100 = 300 | 4 × 10 = 40 | 6 × 1 = 6 |
300 + 40 + 6 = 346. Every number system in this chapter works the same way; only the base changes.
⚡ Binary: base 2
Computer hardware is built from components that have only two states: on or off, charged or not, high voltage or low. That is why everything inside a computer is held as binary codes: base 2, with only the symbols 0 and 1. Each place value is twice the one to its right.
| Place value | 2⁵ = 32 | 2⁴ = 16 | 2³ = 8 | 2² = 4 | 2¹ = 2 | 2⁰ = 1 |
|---|---|---|---|---|---|---|
| Bit | 1 | 0 | 1 | 1 | 1 | 0 |
| Worth | 32 | 0 | 8 | 4 | 2 | 0 |
32 + 8 + 4 + 2 = 46. A binary digit is called a bit. Inside a computer, bits are grouped: the most common group is eight bits, a byte. A byte can hold 2⁸ = 256 different codes. Leading zeros matter inside the machine: the denary number 46 held in a byte is 00101110.
🔣 Hexadecimal: base 16
Hexadecimal (hex) is base 16, so it needs sixteen symbols. After 0–9 it uses the letters A–F for ten to fifteen. Each place value is 16 times the one to its right:
| Place value | 16² = 256 | 16¹ = 16 | 16⁰ = 1 |
|---|---|---|---|
| Digit | 2 | A | 6 |
| Worth | 2 × 256 = 512 | 10 × 16 = 160 | 6 × 1 = 6 |
512 + 160 + 6 = 678. Why bother? Because 16 = 2⁴, one hex digit stands for exactly four bits, a nibble. A byte is two nibbles, so it is always exactly two hex digits:
| Binary byte | Nibbles | Hex | Denary |
|---|---|---|---|
| 00001010 | 0000 | 1010 | 0A | 10 |
| 11111111 | 1111 | 1111 | FF | 255 |
Hex is a shorthand for humans: long binary codes are hard to read, copy or remember, but each byte becomes just two hex digits. It is used for memory dumps (a programmer reading memory contents while debugging) and in tables of character codes. You may meet octal (base 8) elsewhere; it is no longer needed.
🔁 Converting between systems
Binary → denary
Either add up the place values of the 1s, or use the doubling method: start from the most significant bit (MSB, on the left); repeatedly double the running total and add the next bit.
Denary → binary
Method 1, subtract powers of 2: find the largest power of 2 that fits, write 1 there, subtract, and repeat. For 78: 64 fits (left 14), 32 and 16 do not, 8 fits (left 6), 4 fits (left 2), 2 fits (left 0), 1 does not. Reading the 1s and 0s gives 1001110.
Method 2, divide by 2: divide repeatedly by 2 and write down each remainder; the binary number is the remainders read from the last to the first.
Hex ↔ binary ↔ denary
The easiest route between hex and denary usually goes through binary:
- Hex → binary: write each hex digit as four bits.
- Binary → hex: split the bits into fours starting from the right (pad the left group with 0s), then write each group as one hex digit.
- Hex → denary: multiply each digit by its place value (1, 16, 256…), or go via binary.
🔬 Lab: one byte, three ways
Tap bits to switch them on, or type a value in any base.
🎮 Conversion drill
New numbers every time. Answers are marked automatically (spaces are ignored).
🪜 Division stepper
Watch Worked Example 1.02's method on any number up to 65 535.
- 96 = 0110 0000 = 60
- 215 = 1101 0111 = D7
- 374 = 1 0111 0110 → 0001 0111 0110 = 176
- B4 = 11 × 16 + 4 = 180
- FF = 15 × 16 + 15 = 255
- 3A2C = 3 × 4096 + 10 × 256 + 2 × 16 + 12 = 12 288 + 2560 + 32 + 12 = 14 892
No. Inside the hardware everything is held and processed in binary, because the components only have two states. Hex exists for people: software converts binary to hex when it shows us a memory dump, a colour code such as #FF8800, a MAC address or an error code, and converts hex we type back into binary. The computer itself never works in base 16.
📏 1.02 Numbers and quantities
The word number covers several kinds of value:
| Type of number | Example |
|---|---|
| Integer | 35 |
| Signed integer | −35 |
| Fraction | 2/5 |
| A whole number and a fraction | 23.65 |
| Exponential notation | 2.4 × 10³ |
A quantity is a number with a unit. Large quantities are tidied up with exponents: 23 567 m = 23.567 × 10³ m = 23.567 km. The 10³ is replaced by the decimal prefix kilo.
| Name | Symbol | Factor |
|---|---|---|
| kilo | k | 10³ |
| mega | M | 10⁶ |
| giga | G | 10⁹ |
| tera | T | 10¹² |
Computing caused confusion. Memory comes in sizes that are powers of 2, and 2¹⁰ = 1024 is close to 1000, so for years 1 kilobyte was used to mean 1024 bytes. The same computer's specification might quote a 1.6 GHz processor (decimal), 8 GB of RAM (really binary) and a 400 GB disk (decimal). To fix this, the IEC defined binary prefixes:
| Name | Symbol | Factor | Exact value |
|---|---|---|---|
| kibi | Ki | 2¹⁰ | 1024 |
| mebi | Mi | 2²⁰ | 1 048 576 |
| gibi | Gi | 2³⁰ | 1 073 741 824 |
| tebi | Ti | 2⁴⁰ | 1 099 511 627 776 |
Choose the prefix that leaves one or two digits before the decimal point: 34 560 bytes = 34 560 ÷ 1024 = 33.75 KiB; 3 456 000 bytes = 3 456 000 ÷ 1024² ≈ 3.296 MiB.
🔬 Lab: decimal vs binary prefixes
🎮 Prefix drill
➖ 1.03 Internal coding of numbers
This section covers integers only; numbers with fractional parts come in Chapter 16. An integer can be stored unsigned (never negative) or signed.
Unsigned is simple: the binary value, padded to fit the register. A 16-bit register holds 0 to 65 535. The bigger the range needed, the more bits per value.
Sign and magnitude
The obvious way to show a sign is to give it a bit: the leftmost bit is 0 for + and 1 for −, and the rest holds the size of the number. It is easy for people to read but awkward for the processor (see the problems below).
One's complement and two's complement
The one's complement of a binary number flips every bit. The two's complement is the one's complement plus 1. A quicker way to get the two's complement: working from the right, keep every bit up to and including the first 1, then flip all the bits to its left:
To store a signed integer in two's complement:
- Positive: convert to binary and make sure there is a leading 0 (pad with 0s to fill the register).
- Negative: convert the size to binary, add a leading 0, then take the two's complement.
Method 1: the leading 1 means it is negative. Take its two's complement: 01001111 = 64 + 8 + 4 + 2 + 1 = 79. So the number is −79.
Method 2: treat the MSB as worth −128 and the rest as normal: −128 + 32 + 16 + 1 = −79.
Points worth knowing about two's complement:
- There is only one zero (sign and magnitude has +0 and −0).
- The leading bit tells you the sign: 0 positive, 1 negative.
- Taking the two's complement twice gets you back to the start.
- Adding leading 0s to a positive number, or leading 1s to a negative one, does not change its value.
- The range is lopsided: with 8 bits it is −128 to +127.
| Denary | Sign and magnitude | Two's complement |
|---|---|---|
| +7 | 0111 | 0111 |
| +1 | 0001 | 0001 |
| 0 | 0000 | 0000 |
| −0 | 1000 | not represented |
| −1 | 1001 | 1111 |
| −7 | 1111 | 1001 |
| −8 | not represented | 1000 |
🔬 Lab: the −128 register
In two's complement the MSB is worth −128. Tap bits and compare the three readings of the same byte.
🎮 Two's complement drill
Task 1.02: +7 = 0111, so −7 = 1001. Taking the two's complement of 1001: keep the last 1, flip the rest → 0111 = +7.
Task 1.03: 1011 = −8 + 2 + 1 = −5. 111011 = −32 + 16 + 8 + 2 + 1 = −5. The two extra leading 1s add −32 + 16 + 8 = −8, which is exactly what the old MSB was worth, so the value is unchanged: sign extension.
Discussion: keep the last 1 and flip the rest: 1000 → 1000. It is its own complement. 1000 is −8, and +8 cannot be held in four-bit two's complement, so there is one more negative value than positive ones.
➕ Binary arithmetic
Binary addition follows four rules: 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 0 carry 1, and 1 + 1 + 1 = 1 carry 1.
Addition: 11 + 14
Subtraction: 14 − 11
Overflow
In the sum above, the answer needs five bits. If the register only holds a nibble, the result is stored as 1001 and the answer is wrong. That is overflow.
With signed numbers the danger is hidden. In an 8-bit two's complement register:
Adding two numbers of the same sign and getting the opposite sign is the giveaway. Chapter 6 shows how the processor detects this with its status flags.
Two's complement makes subtraction easy: to subtract, add the negative. A − B is calculated as A + (two's complement of B), and any carry out of the register is ignored. The processor needs only an adder.
🎮 Lab: 8-bit adder with overflow check
Add or subtract in 8-bit two's complement. Type the 8-bit result, then say whether the answer overflowed.
🧮 Binary coded decimal (BCD)
Sometimes it is handier to code each denary digit separately. In BCD each digit 0–9 gets its own four-bit code, 0000 to 1001. The codes 1010 to 1111 are never used.
A byte can hold one digit (with four leading 0s), or two digits side by side: packed BCD. Here is 8503 both ways:
| Form | Bytes |
|---|---|
| One digit per byte | 00001000 00000101 00000000 00000011 |
| Packed BCD | 10000101 00000011 |
Where BCD is used: anything that shows digits one at a time, such as a calculator display or a digital clock, because each digit can be sent straight to its own display segment. It is also used for currency: binary cannot hold most decimal fractions exactly (Chapter 16), but BCD keeps every cent exact.
Adding in BCD
Add 0.26 + 0.85 by adding the nibbles as binary:
Figure 1.02 Incorrect BCD addition
The fix: whenever a nibble is above 1001 (or produced a carry), add 0110 (6) to it and carry 1 to the next digit. Six is the gap between 16, where binary carries, and 10, where denary carries.
Figure 1.03 Correct BCD addition
🔬 Lab: BCD encoder
🪜 BCD money adder
Fresh amounts each time. Step through the correction.
🔤 1.04 Internal coding of text
ASCII
For text to be stored and shared, every computer must agree on which code stands for which character. The first widely used standard was ASCII, the American Standard Code for Information Interchange, from the 1960s. It is a 7-bit code, so it has 128 codes. Some of them:
| Character | Binary (in a byte) | Hex | Denary |
|---|---|---|---|
| NUL (null) | 00000000 | 00 | 0 |
| SOH (start of heading) | 00000001 | 01 | 1 |
| space | 00100000 | 20 | 32 |
| # | 00100011 | 23 | 35 |
| 0 | 00110000 | 30 | 48 |
| 1 | 00110001 | 31 | 49 |
| A | 01000001 | 41 | 65 |
| B | 01000010 | 42 | 66 |
| a | 01100001 | 61 | 97 |
| b | 01100010 | 62 | 98 |
What the table shows:
- Some codes are control characters, not printable symbols: NUL, SOH and others were meant to control devices such as printers.
- Most codes are for characters on an English keyboard.
- Digits are in order (0 is 48, 1 is 49 …) and so are letters (A is 65, B is 66 …).
- An upper-case letter and its lower-case partner differ only in bit 5 (counting the least significant bit as bit 0): A is 010 00001 and a is 011 00001. That is a difference of 32.
A digit's code is not its value: the character 1 is 49. Character codes for digits are only for text, such as printing a number; you cannot do arithmetic with them directly.
Over time, countries made their own variations: a UK version swapped # for £, and some codes picked up new meanings (code 1 was often shown as a smiley ☺). Extended ASCII uses all eight bits, giving 256 codes. The extra 128 hold other characters; one widely used set, ISO Latin-1, includes accented letters such as Ç and ü.
Six bits give only 2⁶ = 64 codes. That is enough for the 26 capital letters, the 10 digits, space and about 27 punctuation marks and symbols (ASCII's codes 32–95 are exactly that set). There would be no room for lower-case letters, control characters or any accented or non-Latin characters, unless you used a shift code to switch between two sets.
🌍 Unicode
ASCII only really suits English. Unicode, standardised internationally as ISO/IEC 10646, aims to give every character in every writing system, plus symbols and emoji, its own unique number called a code point. Code points are written U+ followed by at least four hex digits, e.g. U+0041 for A.
The first 128 code points are the same as ASCII, and U+0000 to U+00FF match ISO Latin-1, so older text still makes sense.
UTF-8
A code point must still be stored as bytes. The most widely used encoding is UTF-8, which uses one to four bytes per character:
| Bytes | Pattern | Free bits | Code points |
|---|---|---|---|
| 1 | 0??????? | 7 | U+0000 – U+007F (ASCII) |
| 2 | 110????? 10?????? | 11 | U+0080 – U+07FF |
| 3 | 1110???? 10?????? 10?????? | 16 | U+0800 – U+FFFF |
| 4 | 11110??? 10?????? 10?????? 10?????? | 21 | U+10000 – U+10FFFF |
- A one-byte code starts with 0, so plain ASCII text is already valid UTF-8.
- A lead byte starts with 11; the number of 1s before the first 0 says how many bytes the character uses.
- Every continuation byte starts with 10, so a program that lands in the middle of a character can find where the next one starts.
- The two-byte form has 11 free bits, so it has room for 2¹¹ = 2048 code points. The Latin-1 extras U+0080 to U+00FF are stored as 11000010 10000000 (C2 80) up to 11000011 10111111 (C3 BF).
🔬 Lab: text to codes
Type anything. Each character shows its code point in denary and hex, and its UTF-8 bytes. Bit 5 of letters is highlighted.
🎮 Code-pattern drill
✏️ 1.05 Images: vector graphics
An image can be made in a graphics package, or captured by a camera or a scanner. There are two very different ways to store it.
A vector graphic is built from drawing objects: lines, curves, circles, rectangles, polygons and text. It is what CAD (computer-aided design) and drawing packages produce. The file does not store the picture; it stores a drawing list, one command per object. Each command gives the object's properties, for example:
- its geometry: for a circle, the position of the centre and the radius
- the line: its thickness, style and colour
- The fill colour, if the shape is closed
Using a 100 × 112 box with the origin at the bottom left (any sensible scale is fine):
Marks would go for: one command per object, a position for each, a size (radius, width/height or end points), and line and fill properties.
To display the graphic, the software reads the drawing list and calculates where each object goes. If you ask for it bigger, the file is read again and a new set of calculations is done, so the image stays sharp and in proportion, never squashed or stretched.
Only a graph plotter, an expensive specialised device, can draw a vector graphic directly. For other screens and printers the file usually has to be converted to a bitmap first.
🔬 Lab: edit the drawing list
Commands: CIRCLE cx cy r fill, RECT x y w h fill, LINE x1 y1 x2 y2 colour width. Origin at the bottom left of a 100 × 100 box. Then zoom: the vector is redrawn from the list; the bitmap copy (32 × 32 pixels) is just enlarged.
🟦 Bitmaps
Most images, such as photographs, are not made of neat geometric shapes, so they are stored as bitmaps. Bitmaps come from scanning, screenshots, cameras and simple paint programs.
A bitmap is a two-dimensional grid of pixels (picture elements). A pixel is the smallest part of the image you can identify, and it has only two properties: its position in the grid and its colour. Whether it is shown as a square, a circle or a dot does not matter.
How many bits store each colour? One bit allows only black and white. Four bits allow simple greys. At least eight bits per pixel are needed for a reasonably realistic image. The number of bits per pixel is the colour depth.
A related term is bit depth: the bits used for each of the red, green and blue components in RGB. The two are sometimes mixed up. A colour depth of 8 gives 2⁸ = 256 colours; a bit depth of 8 gives 256 × 256 × 256 = 16 777 216 colours. The eye cannot tell that many apart, but gradual changes such as a blue sky would otherwise show visible bands of colour.
Resolution matters too. The image resolution is pixels per row × number of rows in the file. The screen resolution is how many pixels a particular screen can show. A screen design must consider both.
A bitmap file does not say how big a pixel is in real life. Scaling an image does not change the number of pixels in it: on a suitable screen you cannot see individual pixels, but magnify it too far and they appear.
🔬 Lab: paint a bitmap
📐 Bitmap file size
A large file takes more storage and longer to display or send over a network. A vector file is usually much smaller than an equivalent bitmap. You can calculate a bitmap's size from its resolution and colour depth. A laptop screen of 1366 × 768 with a colour depth of 24:
That assumed the colour depth (bits per pixel) was given. If instead the bit depth is 8, each pixel needs 8 + 8 + 8 = 24 bits.
A real bitmap file is a little larger, because it also starts with a file header describing how the image is coded: at the very least its colour (or bit) depth and resolution.
🎮 File-size drill
Fresh images every time. Give the answer in the unit asked, to one decimal place.
⚖️ Bitmap or vector?
- Choose a vector graphic for a diagram that is part of an architectural, engineering or manufacturing design.
- A vector file must be converted to a bitmap before it can be printed on a laser or inkjet printer.
- A digital camera produces a bitmap automatically.
- A bitmap is the usual choice for putting an image into a document, publication or web page.
🎮 Which would you choose?
🔊 1.06 Sound
Natural sound is a variation in air pressure that the ear detects. A real sound mixes many waves of different frequencies, so its amplitude changes continuously but irregularly.
To store or transmit it, the analogue signal must become binary. A sound encoder does this in two stages:
- A band-limiting filter removes high-frequency components. The ear cannot hear them anyway, and they would cause problems for the coding.
- An analogue-to-digital converter (ADC) turns the analogue data into digital data.
The ADC samples the wave at regular times (the blue lines). It cannot measure the amplitude exactly, so each sample is rounded to the nearest of a fixed set of levels (the horizontal lines). In Figure 1.07, samples 1 and 4 land on a level and are accurate; samples 5 and 6 fall about halfway between two levels and are not.
Two decisions control the quality:
- Sampling resolution: how many bits store each sample. Three bits give only 8 levels, as in the figure, so the rounding error is large. 16 bits is reasonable for most digitised sound.
- Sampling rate: how many samples are taken per second. Nyquist's theorem says you must sample at least twice the highest frequency in the sound.
Raising either the sampling rate or the resolution makes the copy more faithful, and makes the file bigger.
🔬 Lab: sample a wave
🎮 Sound file-size drill
🗜️ 1.07 Compression techniques
Big files need more storage, and, more importantly, take longer to transmit or download. Compression makes them smaller. There are two kinds:
Many real formats combine both.
Every file is binary, so one general lossless method could compress anything: a good program spots repeated patterns without knowing what the file is. In practice most techniques are designed for one type of file.
Run-length encoding (RLE): lossless, good for bitmaps
RLE replaces a run of identical bytes with a count and one copy of the byte. Four identical bytes:
A real scheme also needs a way to tell a count byte from a data byte; there are several, and you do not need the details.
🔬 Lab: run-length encode a row of pixels
W = white pixel, B = black pixel, one byte each before compression.
Huffman coding: lossless, good for text
Text must be compressed losslessly, because one wrong character changes the meaning. Huffman coding analyses the text, then gives the most frequent characters the shortest codes instead of a full byte each. The bytes become a bit stream. If a text used only eight letters, the codes could be:
| Code | Character |
|---|---|
| 10 | e |
| 01 | t |
| 111 | o |
| 110 | h |
| 0001 | l |
| 0000 | p |
| 0011 | w |
| 0010 | z |
The key is the prefix property: no code is the start of a longer code. So when decoding the bit stream there is never any doubt where one character ends.
🎮 Lab: decode the bit stream
Use Table 1.10. Read bits from the left until they match a code, write that letter, carry on.
Other file types
- Sound, lossless: Huffman coding works because some amplitude values occur much more often than others.
- Vector graphics: best converted to Scalable Vector Graphics (SVG), a markup-language description that compresses well losslessly.
- Sound, lossy: neighbouring samples rarely differ much, so store the differences between samples using fewer bits. Or transform the samples from the time domain into the frequency domain, re-code the barely audible frequencies with fewer bits, then transform back.
- Bitmaps, lossy: choose a scheme with a smaller colour depth and replace each pixel's colour with the closest colour in the new scheme.
🎮 Lossy or lossless?
- JPEG: lossy. The image is split into 8 × 8 blocks, transformed into frequencies (a discrete cosine transform), and fine detail the eye barely notices is stored with fewer bits. The result is then compressed losslessly with run-length and Huffman coding.
- GIF: lossless LZW compression, but limited to a palette of 256 colours, so converting a photo to GIF loses colour information (just like reducing the colour depth).
- PNG: lossless DEFLATE compression (LZ77 pattern matching plus Huffman coding), with full colour and transparency.
- TIFF: a container that can be uncompressed, or use lossless LZW, ZIP or RLE (PackBits), or even JPEG inside.
An unsigned integer (0–255); a signed integer in two's complement (−128 to 127); part of a larger number; two packed BCD digits (or one unpacked); an ASCII or Latin-1 character; one byte of a multi-byte UTF-8 character; a pixel's colour (colour depth 8) or one RGB component; part of a sound sample; an RLE count; part of a file header; a machine-code instruction or part of an address (Chapter 6). The byte itself never says which: the program reading it decides.
📌 Summary
- Any binary code or number can be written down as hexadecimal.
- Signed integers are usually coded in two's complement.
- Binary addition can cause overflow.
- BCD is a convenient code for single denary digits.
- ASCII and Unicode are standard coding schemes for text.
- An image can be stored as a vector graphic or as a bitmap.
- An ADC works by sampling a continuous waveform.
- Lossless compression lets a decoder recover the original file; lossy compression loses some information for good.
🃏 Key-term flashcards
Tap a card to flip it.
✅ Quick quiz
📝 Exam-style questions
Write your answer first, then open the model answer. These are my mark-scheme-style points, not official mark schemes.
Question 1 uses two successive bytes from a file: 10010101 and 00110011.
(i) 1001010100110011 = 32 768 + 4096 + 1024 + 256 + 32 + 16 + 2 + 1 = 38 195.
(ii) Group in fours: 1001 0101 0011 0011 = 9533. (Check: 9 × 4096 + 5 × 256 + 3 × 16 + 3 = 38 195.)
Any one: a memory dump when debugging; HTML/CSS colour codes such as #FF0000; MAC addresses; error codes; assembly-language addresses.
(i) 10010101 is negative, because its most significant (sign) bit is 1.
(ii) 10010101 = −128 + 16 + 4 + 1 = −107. 00110011 = 32 + 16 + 2 + 1 = 51.
- There is only one representation of zero.
- Addition works on positive and negative numbers with the same circuit, and subtraction is done by adding the complement, so the processor needs no separate subtractor or sign logic.
- One extra value fits in the range (e.g. −128 in a byte).
- Two ASCII characters: one byte each.
- One Unicode character (a two-byte UTF-8 or UTF-16 code): both bytes.
- Four BCD digits (packed): part of a byte (a nibble) each.
- A 16-bit sound sample or a pixel with colour depth 16: both bytes.
(i) The file holds a drawing list: a command for each drawing object (line, circle, rectangle…) with its properties such as position, size, line and fill colour. The image is calculated from the list when displayed.
(ii) The image is a grid of pixels; the file holds a colour code for every pixel (colour depth bits each), plus a header with the resolution and colour depth.
(iii) Vector. It is redrawn from its geometric definitions at the new size, so edges stay sharp. A bitmap has a fixed number of pixels, which are just made bigger, so they become visible (pixelation).
(i) 640 × 480 × 16 = 4 915 200 bits ÷ 8 = 614 400 bytes ÷ 1024 = 600 KiB (about 0.59 MiB).
(ii) The file also contains a header (and possibly other metadata), which adds to the size.
(i) Run-length encoding: a run of pixels with the same colour is replaced by a count and one copy of the colour code. It can be decoded back to exactly the original.
(ii) Reduce the colour depth: define a scheme with fewer colours and replace each pixel's colour with the closest one in the new scheme. Fewer bits per pixel, but the original colours are lost. (Or: discard fine detail the eye is unlikely to notice, as JPEG does.)
(i) Sound is analogue: its amplitude varies continuously. A computer can only store and process discrete binary values, so the signal must be sampled and each sample converted to a binary number.
(ii)
- Sampling rate: the number of samples taken per second (e.g. 44 100 Hz).
- A higher rate captures the shape of the wave more faithfully; it should be at least twice the highest frequency (Nyquist).
- Sampling resolution: the number of bits used to store each sample.
- It sets the number of amplitude levels (2ⁿ for n bits); each sample is rounded to the nearest level, so more bits mean smaller rounding errors.
- Raising either one increases the file size.
A diagram like Figure 1.07: a wave, vertical lines at the sampling times, horizontal lines for the levels.
(i) A band-limiting filter.
(ii) It removes high-frequency components. The human ear cannot hear them, so nothing useful is lost, and if they were left in they would cause problems (distortion) when the signal is sampled and coded.
(i) 124 = 01111100. 77 = 01001101, so −77 = 10110011.
(ii) 0111 1100 = 7C; 1011 0011 = B3.
(i) 0011 0101 1001
(ii) A calculator or digital clock display: each digit is held separately, so its four-bit code can be sent straight to the display for that digit. Or: currency values, because BCD holds decimal amounts exactly with no rounding errors.
Cambridge International AS & A Level Computer Science 9608, Paper 13 Q1, June 2015
- Sampling resolution: the number of bits used to store each sample…
- …so it sets how many amplitude levels can be represented, and how accurate each sample is.
- Sampling rate: the number of samples taken per second…
- …so a higher rate records the changes in the wave more accurately (at least twice the highest frequency).
(i) 44 100 × 16 × 2 = 1 411 200 bits ÷ 8 = 176 400 bytes per second.
(ii) Multiply by 4 × 60 = 240 seconds: 176 400 × 240 = 42 336 000 bytes. Divide by 1 000 000 for megabytes (≈ 42.3 MB), or by 1024 × 1024 for mebibytes (≈ 40.4 MiB).
- It uses lossy, perceptual coding based on what the human ear can actually hear.
- Frequencies outside the range of human hearing are removed.
- Quiet sounds that are masked by louder sounds at the same moment are removed.
- Less important frequencies are stored with fewer bits; the result is then compressed losslessly (e.g. Huffman coding).
- The data removed is data the listener would hardly notice, so the music sounds almost the same.
Cambridge International AS & A Level Computer Science 9608, Paper 12 Q4, November 2015
Guru Jazzy · Cambridge AS & A Level Computer Science · Chapter 1 Information Representation · Figures from the Cambridge coursebook (Langfield & Duddell)