Binary, denary and hexadecimal
A computer keeps every value as a row of ons and offs: binary (base 2), easy for it and hard for us to read. People count in denary (base 10); programmers shorten binary to hexadecimal (base 16). All three write the same number.
Inside a computer every value is a pattern of ons and offs: binary (base 2). People count in denary (base 10), and programmers often write the shorter hexadecimal (base 16). All three write the same number.
Start from the bits at the top: they split into three groups of four, and each group becomes one hex digit.
Three conversions, one example
Every card converts the same value, 459, so you see one number in all three bases. Be able to do each conversion in both directions.
Denary → binary
Write the place values. Subtract the largest that fits and write 1 under it; otherwise write 0.
Binary ↔ hexadecimal
Split the bits into groups of four from the right. Each group is one hex digit; pad the left group with 0s.
Hexadecimal ↔ denary
To denary, multiply each digit by its place value (256, 16, 1). To hex, divide by 16 repeatedly and read the remainders upwards.
How many values can n bits hold?
Each extra bit doubles the number of patterns. Read a row of the table for one bit width; the card goes the other way, from a count of values to the bits it needs.
| Unsigned | Different patterns | Denary range | Largest in hex |
|---|---|---|---|
| 4 bits | 24 = 16 | 0 to 15 | F |
| 8 bits | 28 = 256 | 0 to 255 | FF |
| 12 bits | 212 = 4 096 | 0 to 4 095 | FFF |
| 16 bits | 216 = 65 536 | 0 to 65 535 | FFFF |
Minimum number of bits
- 1n bits give 2ⁿ patterns; the largest unsigned value is 2ⁿ − 1.
- 2For k different values, find the smallest n with 2ⁿ ≥ k.
- 3128 values (0 to 127) need 7 bits; the number 128 itself needs 8.
- 440 000 values need 16; 5 000 000 need 23.
1 Convert 182 to 8-bit binary, then to hexadecimal.
2 Convert the hexadecimal 3E to denary.
3 How many bits are needed to store 300 different values?
4 What is the largest unsigned value 10 bits can hold?
- 11011 0110, so B6: 1011 → B, 0110 → 6
- 23 × 16 + 14 = 62
- 39: 2⁸ = 256 is too few, 2⁹ = 512 is enough
- 42¹⁰ − 1 = 1023
0000 1010 1011, leading zeros included. One hex digit is four bits.Binary magnitudes and prefixes
A single photo holds millions of bits, so nobody counts them one at a time. A bit is one binary digit; 4 bits make a nibble and 8 make a byte. Bigger amounts take a prefix, and two sets of prefixes sound alike but name different sizes: binary (powers of 2) and decimal (powers of 10).
Follow the ladder from bit to TiB: the number under each arrow is how many of one unit make the next.
Decimal prefixes count in 1000s; binary prefixes count in 1024s
Prefixes that sound alike can name different sizes: a kibibyte is 24 bytes more than a kilobyte. Be able to name both prefixes in a row and give each one’s size in bytes.
| Decimal prefix | Bytes | Binary prefix | Bytes |
|---|---|---|---|
| kilo (kB) | 103 = 1 000 | kibi (KiB) | 210 = 1 024 |
| mega (MB) | 106 = 1 000 000 | mebi (MiB) | 220 = 1 048 576 |
| giga (GB) | 109 = 1 000 000 000 | gibi (GiB) | 230 = 1 073 741 824 |
| tera (TB) | 1012 = 1 000 000 000 000 | tebi (TiB) | 240 = 1 099 511 627 776 |
| Decimal | Binary |
|---|---|
| kilo (kB) 103 = 1 000 bytes | kibi (KiB) 210 = 1 024 bytes |
| mega (MB) 106 = 1 000 000 bytes | mebi (MiB) 220 = 1 048 576 bytes |
| giga (GB) 109 = 1 000 000 000 bytes | gibi (GiB) 230 = 1 073 741 824 bytes |
| tera (TB) 1012 = 1 000 000 000 000 bytes | tebi (TiB) 240 = 1 099 511 627 776 bytes |
Worked conversions
The first two cards start from the same 2 and end 777 216 bits apart, because one prefix steps by 1024 and the other by 1000.
2 MiB in bits
2 MB in bits
4.5 MiB photos on 16 GiB
- Bits to bytes: ÷ 8. Then ÷ 1024 for each binary prefix step, or ÷ 1000 for each decimal step.
- Use the prefix the question names.
- To compare sizes, convert to the same unit first: 2 MiB is 2 097 152 bytes, more than 2 MB (2 000 000 bytes).
1 How many bytes are in 3 KiB?
2 How many bits are in 5 MB?
3 Which is larger, 1 GiB or 1 GB? By how many bytes?
4 How many whole 2.5 MiB files fit in 1 GiB?
- 13 × 1024 = 3 072 bytes
- 25 × 1000 × 1000 × 8 = 40 000 000 bits
- 31 GiB, by 1 073 741 824 − 1 000 000 000 = 73 741 824 bytes
- 41024 ÷ 2.5 = 409.6, so 409 whole files
Hexadecimal in use
A row of thirty-two 0s and 1s is easy to misread and hard to copy. Hexadecimal is a shorthand for binary: one hex digit stands for exactly four bits, so that row shrinks to eight digits. It is used wherever people need to read, write or check long binary values.
The sixteen hex digits
Read the strip down each column: a hex digit, its four bits and its denary value. Converting is swapping a digit for its column.
| Hex | Binary | Denary |
|---|---|---|
| 0 | 0000 | 0 |
| 1 | 0001 | 1 |
| 2 | 0010 | 2 |
| 3 | 0011 | 3 |
| 4 | 0100 | 4 |
| 5 | 0101 | 5 |
| 6 | 0110 | 6 |
| 7 | 0111 | 7 |
| Hex | Binary | Denary |
|---|---|---|
| 8 | 1000 | 8 |
| 9 | 1001 | 9 |
| A | 1010 | 10 |
| B | 1011 | 11 |
| C | 1100 | 12 |
| D | 1101 | 13 |
| E | 1110 | 14 |
| F | 1111 | 15 |
Practical applications of hexadecimal
Hex turns up wherever people handle long binary values by eye, from web colours to network cards. Be able to give a use and say why hex suits it.
| Where hexadecimal is used | Why hex is used |
|---|---|
| Memory addresses and memory dumps | a long address or a block of memory contents is far shorter to read and check |
| Colour codes in web pages and graphics | #D9752B is three pairs of hex digits: red D9, green 75, blue 2B |
| MAC addresses and IPv6 addresses | 48-bit and 128-bit values become 12 and 32 hex digits |
| Machine code, assembly and error codes | a programmer can read and debug the values with fewer mistakes |
Read a colour code and a MAC address
A colour code
A MAC address
00:1A:2B:3C:4D:5E
12 hex digits stand for the 48-bit address. Written in binary it would be 48 digits long.
1 A web page uses the colour #3C8F1A. What is its red value in denary?
2 Write the hex value 7E as 8 bits.
3 A memory address is 32 bits long. How many hex digits does it take?
4 Why does a technician read a memory dump in hex rather than in binary?
- 13C → 3 × 16 + 12 = 60
- 27 → 0111, E → 1110: 0111 1110
- 332 ÷ 4 = 8
- 4hex is four times shorter, so it is quicker to read and fewer digits are miscopied
Binary coded decimal (BCD)
A digital clock shows each digit on its own, so it can store them that way too. Binary coded decimal (BCD) gives each denary digit its own 4-bit code; the number is never converted as a whole.
Each digit of 409 gets its own four bits. Under the boxes, compare that with 409 converted as a whole.
The same bits, read two ways
One pattern, two numbers: say which reading you are using before you work out a value.
| Read 0100 1001 as… | Working | Value |
|---|---|---|
| unsigned binary | 64 + 8 + 1 | 73 |
| BCD | 0100 → 4, 1001 → 9 | 49 |
Binary → BCD
Convert the binary to denary first, then code each denary digit:
Do not confuse
A BCD nibble only holds 0000 to 1001 (0–9). 1010 to 1111 are not BCD digits, so 0110 1011 cannot be BCD: its second nibble, 1011, is 11.
Practical applications of BCD
BCD takes more bits than plain binary, so it is chosen only where keeping each denary digit separate helps. Be able to give an application and a reason that fits that application.
| Application | Why BCD suits it |
|---|---|
| Calculator, clock or meter display | Each position on the display shows one denary digit, so each 4-bit code drives one position directly, with no conversion of the whole number. |
| Money in a till or a bank account | Decimal digits are held exactly. A decimal fraction such as 0.10 has no exact finite binary fraction, so storing fractional amounts that way can introduce rounding errors. |
| Date and time kept by a PC's BIOS clock | Each digit of the time has its own nibble, so it is read, shown and set digit by digit, and turned into denary simply. |
| Barcode systems | Each printed digit maps to its own 4-bit code, making conversion back to the denary digits straightforward. |
1 Write 75 in BCD.
2 Which denary number is the BCD code 0011 1000 0110?
3 Can 1001 1100 be a BCD code? Give the reason.
4 Write the binary number 0101 1010 in BCD.
- 17 → 0111, 5 → 0101: 0111 0101
- 20011 → 3, 1000 → 8, 0110 → 6: 386
- 3no: the second nibble, 1100, is 12, above 9
- 40101 1010 = 90, so 1001 0000
One’s and two’s complement
Plain binary only counts up from 0, but a bank balance or a temperature can drop below zero, and a byte has no minus sign. A signed integer can be negative. In one’s complement a negative is the positive number with every bit flipped; in two’s complement every bit is flipped, then 1 added.
Where the negative numbers sit
Laid out in denary order, the 256 patterns of 8-bit two’s complement split into a negative half and a positive half. Be able to tell the sign from the first bit.
Convert in both directions
One route each way: build −45 from +45, then read 1101 0011 back by giving its left bit the value −128.
Denary → two’s complement
Step 2 alone gives the one’s complement of +45: 11010010 = −45 in one’s complement.
Two’s complement → denary
Method 1: the most significant bit has a negative place value; add the place values that hold a 1.
Method 2: invert and add 1 to find the size: 00101100 + 1 = 00101101 = 45, so the value is −45.
Compare the three representations
Each form gives up something: negative numbers, a wider range, or a single zero. Be able to give the range, the zeros and how a negative is formed for each.
| 8-bit form | Range | Zero | Negative numbers |
|---|---|---|---|
| Unsigned | 0 to 255 | one zero | not represented |
| One’s complement | −127 to +127 | two: 00000000 and 11111111 | invert every bit of the positive value |
| Two’s complement | −128 to +127 | one: 00000000 | invert every bit, then add 1 |
Two more facts come from the two’s complement row: how to widen a number, and the range for any number of bits.
Widening a two’s complement number
Copy the sign bit into the new places. 1101 (−3 in 4 bits) becomes 1111 1101 (−3 in 8 bits); 0101 becomes 0000 0101.
Limits in n bits
Two’s complement covers −2ⁿ⁻¹ to +2ⁿ⁻¹ − 1. Smallest: 1 then all 0s; largest: 0 then all 1s. 8 bits: 1000 0000 = −128 to 0111 1111 = +127. 16 bits: −32 768 to +32 767.
1 Write −20 in 8-bit two’s complement.
2 Which denary value is the two’s complement number 1011 0110?
3 Write −20 in 8-bit one’s complement.
4 Widen the 4-bit two’s complement number 1010 to 8 bits. What value does it hold?
- 1+20 = 0001 0100 → invert 1110 1011 → add 1: 1110 1100
- 2−128 + 32 + 16 + 4 + 2 = −74
- 31110 1011: invert only
- 4copy the sign bit: 1111 1010, still −6
Binary addition, subtraction and overflow
Binary sums work like the column sums you already know, with only two digits. Add column by column from the right: 1 + 1 = 10, so write 0 and carry 1. Subtract by adding the two’s complement. The catch is the fixed number of bits: overflow happens when the result needs more bits than there are.
Add from the right, carrying to the left
Learn the four rules, then follow them through two 8-bit sums that both run out of room, in different ways.
Rules
Unsigned: 200 + 100
300 needs 9 bits. The ninth bit has nowhere to go: overflow. The 8 bits that remain hold 44.
Two’s complement: 100 + 40
Two positive numbers give a result starting with 1, which reads as −116: overflow, because +140 is above +127.
For three numbers, add the first two, then add the third to that result. Show both sets of binary working and keep any carry-out bits the question requests.
Two ways to subtract
A computer subtracts by adding the two’s complement; on paper you can also borrow, as in denary column subtraction.
Subtract by adding: 94 − 37
Form −37: 00100101 → invert → +1 → 11011011. Then add.
The carry out of the left-most column (struck through) is discarded, not overflow: the answer is +57.
Direct subtraction: 113 − 46
Where a column has 0 − 1, borrow from the next column to the left (marked 1 above it). The answer is 0100 0011 = 67.
Follow 94 + (−37) one column at a time
Most slips happen in the carries, so follow one sum slowly. Each row is one column, named by its place value; start at the 1 column. A row adds two bits and the carry in, writes one bit and carries the rest left. The highlighted column uses 1 + 1 + 1 = 11.
| 94 | −37 | Carry in | Write | Carry out | What happens in the column | |
|---|---|---|---|---|---|---|
| 1 | 0 | 1 | 1 | 0 + 1 = 1: write 1 | ||
| 0 + 1 = 1: write 1 | ||||||
| 2 | 1 | 1 | 0 | 1 | 1 + 1 = 10: write 0, carry 1 | |
| 1 + 1 = 10: write 0, carry 1 | ||||||
| 4 | 1 | 0 | 1 | 0 | 1 | 1 + 0 + carry 1 = 10: write 0, carry 1 |
| 1 + 0 + carry 1 = 10: write 0, carry 1 | ||||||
| 8 | 1 | 1 | 1 | 1 | 1 | 1 + 1 + carry 1 = 11: write 1, carry 1 |
| 1 + 1 + carry 1 = 11: write 1, carry 1 | ||||||
| 16 | 1 | 1 | 1 | 1 | 1 | 1 + 1 + carry 1 = 11: write 1, carry 1 |
| 1 + 1 + carry 1 = 11: write 1, carry 1 | ||||||
| 32 | 0 | 0 | 1 | 1 | 0 + 0 + carry 1 = 1: write 1 | |
| 0 + 0 + carry 1 = 1: write 1 | ||||||
| 64 | 1 | 1 | 0 | 1 | 1 + 1 = 10: write 0, carry 1 | |
| 1 + 1 = 10: write 0, carry 1 | ||||||
| 128 | 0 | 1 | 1 | 0 | 1 | 0 + 1 + carry 1 = 10: write 0, carry 1; the carry out is discarded |
| 0 + 1 + carry 1 = 10: write 0, carry 1; the carry out is discarded | ||||||
Overflow
- The result is too large (or too small) to fit in the bits available, so the stored value is wrong.
- Unsigned: a carry out of the most significant bit, as in 200 + 100.
- Two’s complement: two numbers with the same sign give a result with the opposite sign, as in 100 + 40. A carry out when subtracting by adding is discarded and is not overflow.
1 Add 0101 0111 + 0010 1101.
2 Read your answer to question 1 as an 8-bit two’s complement number. Has overflow happened?
3 In 8-bit unsigned binary, 190 + 85 is worked out. What is stored, and why is it wrong?
4 Work out 75 − 28 by adding the two’s complement of 28.
- 11000 0100
- 2yes: two positive numbers gave a result starting with 1, which reads as −124; +132 is above +127
- 30001 0011 = 19: 275 needs 9 bits, so the carry out is lost (overflow)
- 4−28 = 1110 0100; 0100 1011 + 1110 0100 = (1) 0010 1111 = 47; the carry out is discarded
Character sets
A computer can only store numbers, so to keep a letter it stores a number that stands for it. A character set lists every character a computer can represent and gives each one a unique binary code.
Text is stored as a sequence of character codes
The computer swaps every character for its code and keeps the codes in sequence, in the order of the text.
ASCII, extended ASCII and Unicode
Seven bits are enough for English but not for the world’s scripts, which is why there are several sets. Be able to compare them: bits per character, how many characters, and what they cover.
| Character set | Bits per character | Characters | Covers |
|---|---|---|---|
| ASCII | 7 | 2⁷ = 128 | English letters, digits, punctuation and control characters |
| Extended ASCII | 8 | 2⁸ = 256 | ASCII plus extra symbols and some accented letters |
| Unicode | up to 32, depending on encoding | far more | characters from many languages, plus symbols and emojis; includes all the ASCII characters |
| Set | Bits, characters and coverage |
|---|---|
| ASCII | 7 bits · 2⁷ = 128 characters English letters, digits, punctuation and control characters |
| Extended ASCII | 8 bits · 2⁸ = 256 characters ASCII plus extra symbols and some accented letters |
| Unicode | up to 32 bits, depending on encoding · far more characters characters from many languages, plus symbols and emojis; includes all the ASCII characters |
What every set shares, and what changes as the sets grow:
Alike
- In either set, every character is given its own unique binary code.
- The first 128 Unicode codes are the ASCII codes: ASCII is a subset of Unicode.
- An English letter can take 8 bits in either (Unicode’s 8-bit encoding).
Different
- Unicode allows up to 32 bits for a character; ASCII has 7, or 8 when extended.
- More bits give far more codes, so Unicode covers the scripts of many languages, plus emojis.
- The cost: the same text can need more storage in Unicode.
1 In ASCII the code for 'A' is 65. What is the code for 'E'? Write it in 8 bits.
2 How many bits does the word “Hello” take in 8-bit ASCII?
3 In ASCII the digit '7' has the code 55. What is the code for '9'?
4 A messaging app must send Greek and Thai text. Why does it use Unicode, not ASCII?
- 169: 0100 0101
- 25 characters × 8 bits = 40 bits
- 357: the digits have consecutive codes
- 4ASCII has only 128 (or 256) codes, mostly English; Unicode uses more bits, so it has codes for the characters of many languages
Bitmap images: how the data is encoded
Zoom right into a photo and you see tiny squares of colour. A bitmap image is a grid of these pixels, and every pixel is one colour. Each colour the image uses has its own unique binary code, and the file holds the code for every pixel, one after another in sequence.
Match each square to its code in the key, then find that code in the pixel data: the top row reads 00 00 01 01 10 10.
Terms to use precisely
Image resolution and screen resolution sound alike but mean different things, so each term needs its exact meaning. Be able to define each one, keeping the words in bold.
| Term | Meaning |
|---|---|
| Pixel | the smallest addressable part of an image: one square that holds one colour |
| File header | information that describes the image, stored before the pixel data: file type, file size, width and height, colour depth, compression type, where the pixel data starts |
| Image resolution | the image’s size in pixels: its width in pixels × its height in pixels |
| Screen resolution | the width × height in pixels that a screen can display |
| Colour depth (bit depth) | how many bits each pixel uses for its colour; n bits give 2ⁿ possible colours |
Two mix-ups to avoid:
Image or screen resolution?
Changing the screen resolution does not change the stored image. A screen with fewer pixels than the image cannot show every one of them, so the picture looks less sharp.
Do not confuse
A pixel is the picture element, not its binary code. The header describes the image; it does not hold the pixel colours.
1 An image uses 9 different colours. What is the smallest colour depth it can have?
2 An image is 10 pixels wide and 8 high, with a colour depth of 1 bit. How many bits of pixel data does it have?
3 Which part of the file tells the software how wide the image is?
4 In the figure, which colour is the third pixel of the top row, and what code is stored for it?
- 14 bits: 3 bits give only 8 codes, 4 bits give 16
- 210 × 8 × 1 = 80 bits
- 3the file header
- 4pale blue: 01
Bitmap images: file size and quality
Every pixel costs the same number of bits, so the size of a bitmap is easy to predict. The file size is width × height × colour depth in bits. Then convert to the unit you need.
Estimate the file size
Three images, one method: each card multiplies the same three things, and the amber card shows the trap when the depth is already in bytes. All are uncompressed pixel data, without the header unless a header size is given.
For uncompressed pixel data, multiply the number of pixels by the bits per pixel, then convert to the unit the question asks for. The estimate excludes the header unless a header size is given.
Answer in mebibytes
Answer in megabytes
Depth given in bytes
Effects of changing a bitmap
Most changes trade picture quality against file size. Be able to say what each change does to the image and to the file size, and why.
| Change | Effect on the image | Effect on the file size |
|---|---|---|
| Increase the image resolution | more pixels can record finer detail and reduce pixelation | larger: more pixels to store |
| Decrease the image resolution | fewer pixels, so detail is lost | smaller: fewer pixels to store |
| Increase the colour depth | more colours available, so recorded colours can be closer to the original | larger: more bits for every pixel |
| Decrease the colour depth | fewer colours available, so detail is lost | smaller: fewer bits for every pixel |
| Double the width and the height | 4 × as many pixels | 4 × as large (same depth) |
| Repaint one area in a different colour | the picture looks different | no change: the same pixels, the same bits each |
| Show the image on a screen with more or fewer pixels | the display changes, the stored image does not | no change |
1 An image is 1024 × 512 pixels with a colour depth of 8 bits. What is its file size in KiB?
2 An image may use up to 64 colours. What colour depth does it need?
3 The width and the height of an image are both halved. What happens to the file size?
4 An image is 1000 × 500 pixels with 2 bytes per pixel. What is its size in MB?
- 11024 × 512 × 8 = 4 194 304 bits ÷ 8 = 524 288 bytes ÷ 1024 = 512 KiB
- 26 bits: 2⁶ = 64
- 3a quarter of the pixels, so a quarter of the size
- 41000 × 500 × 2 = 1 000 000 bytes (already bytes: no ÷ 8) ÷ 1000 ÷ 1000 = 1 MB
Bitmap sequences: counting frames and file size
An animation is a flick-book of still bitmaps, called frames, shown fast enough to look like movement. Take the 2048 × 768 image you sized earlier, with 4 bits per pixel, and make every frame that size. It plays 12 frames each second for 3 seconds.
Each box is one frame of 0.75 MiB: a row is one second of 12 frames, and three rows make the 3 seconds.
Size per frame × number of frames
1 · Size of one frame
2 · Count and combine the frames
Choose the right factors
A question may give the number of frames, or the frame rate and the length, and may add headers or sound. Each needs a different step. Be able to choose which factor each given value needs.
| Given | What to do |
|---|---|
| A number of frames | multiply the one-frame size by that count |
| Frames per second and duration | first multiply frames/s × seconds to count frames |
| Depth in bytes rather than bits | the per-frame result is already bytes: do not divide by 8 again |
| A sound track or stated headers | calculate those separately and add them in the same units |
1 A clip is 800 × 600 pixels with 8 bits per pixel. How many bytes is one frame?
2 The clip plays 25 frames each second for 4 seconds. How many frames is that?
3 What is the size of the whole clip in MB?
4 The same clip is stored with 2 bytes per pixel instead. What is its size in MB?
- 1800 × 600 × 8 = 3 840 000 bits ÷ 8 = 480 000 bytes
- 225 × 4 = 100 frames
- 3480 000 × 100 = 48 000 000 bytes = 48 MB
- 4800 × 600 × 2 = 960 000 bytes a frame × 100 = 96 MB
Vector graphics
A logo has to look sharp on a business card and on the side of a bus. A vector graphic does not store pixels. It stores a drawing list: a description of each object, from which the image is calculated whenever it is displayed, at whatever size it is needed.
Match each shape on the grid to its entry in the drawing list: the entry holds coordinates and settings, never pixels.
Drawing object
One shape or piece of text in the image: a line, a rectangle, a circle or a letter.
Property
A setting that fixes how one drawing object looks: its fill colour, line colour, line width or font.
Drawing list
Every drawing object in the image, each stored with the command and the property values that draw it.
What the drawing list stores for each object
The drawing list is all a vector file holds, so everything you see on screen has to be written in it. Be able to name properties for an object and say what else its entry stores.
| Object | Properties (its appearance) | Also in the drawing list (where and how big) |
|---|---|---|
| Line | line colour, line width, style (solid, dashed) | start and end coordinates |
| Rectangle | fill colour, line colour, line width | corner position, width, height |
| Circle | fill colour, line colour, line width | centre coordinates, radius |
| Text | font, font size, colour | the characters and their position |
| Object | Appearance and geometry |
|---|---|
| Line | line colour, line width, style (solid, dashed) start and end coordinates |
| Rectangle | fill colour, line colour, line width corner position, width, height |
| Circle | fill colour, line colour, line width centre coordinates, radius |
| Text | font, font size, colour the characters and their position |
1 Give two properties of the circle in the drawing list.
2 The whole image is enlarged 2 times from (0, 0). Give the rectangle’s new corner, width and height.
3 Which object in the drawing list has no fill colour, and why?
4 Why do the edges stay sharp when a vector graphic is enlarged?
- 1any two of: fill colour (pale violet), line colour (violet), line width 2
- 2corner (20, 110), width 80, height 60
- 3the line: it encloses no area to fill, so it has only a line colour and a line width
- 4the shapes are drawn again from the new coordinates, not by making pixels bigger
Bitmap or vector: justify the choice
Neither kind of image is better everywhere. A bitmap stores every pixel, which suits a photograph; a vector graphic stores a drawing list, which suits shapes that must scale. Choose by what the image shows and how it will be used.
Both images started as the same small circle and were enlarged by the same amount.
Compare the same feature for both
A comparison is only clear when both halves talk about the same feature. Be able to give each difference as a pair: a bitmap …, whereas a vector graphic ….
| Bitmap | Vector graphic | |
|---|---|---|
| What is stored | a colour code for every pixel | a drawing list of objects and their properties |
| File size | grows with the pixel count: every pixel is stored | for a simple image, small: one entry per object |
| When enlarged | each pixel is drawn bigger, so blocks show (pixelation) | sizes are recalculated, so edges stay sharp |
| Editing | single pixels can be changed, e.g. retouching | one object can be changed without touching the rest |
| Compression | runs of same-coloured pixels shrink well, e.g. with RLE | a short drawing list has little repetition to remove |
| Suits | photographs: many colours, fine detail | logos, diagrams and plans made of shapes |
Justify the choice for the task
Two jobs, two choices: each reason ties a feature of the format to what that job needs.
A cycle club’s badge as a vector graphic
- It goes on jerseys, flags and a phone app, so it must scale without pixelation.
- It is a few shapes and letters, so its drawing list is short and the file small.
- One shape can be changed on its own if the club updates the badge.
A scanned watercolour as a bitmap
- The painting has many colours and fine brush detail, which pixels record.
- Single pixels can be retouched, e.g. to remove a speck of dust.
- As objects it would need an enormous drawing list.
1 A school puts the floor plan of its buildings on its website. Visitors zoom in to find rooms. Bitmap or vector? Give a reason.
2 A photographer sells prints of a sunset. Bitmap or vector? Give a reason.
3 Give one difference between a bitmap and a vector graphic as a pair.
- 1vector: the plan is lines and shapes, so its drawing list is short, and zooming recalculates it without pixelation
- 2bitmap: a photograph has many colours and fine detail, which pixels record
- 3for example: a bitmap shows blocks when enlarged, whereas a vector graphic is recalculated and stays sharp
Sound: sampling and encoding
A sound wave rises and falls smoothly, with no gaps: it is analogue. A computer can only keep separate numbers, so it measures the wave at regular intervals and stores each measurement as a binary number.
Each dot is one sample. It is rounded to the nearest of the 16 levels, and that level’s code is written underneath.
Terms
Sampling rate and sampling resolution are easy to swap, and each changes the sound in a different way. Be able to define each term, keeping the words in bold.
| Term | Meaning |
|---|---|
| Analogue data | continuous: the sound wave can take any value at any moment |
| Digital data | discrete: a set of separate binary values |
| Sampling | measuring the amplitude of the sound wave at regular intervals |
| Sampling rate | how many samples are taken each second, in hertz: 16 kHz = 16 000 samples a second |
| Sampling resolution | how many bits hold each sample: n bits give 2ⁿ amplitude levels |
1 Which code is stored for the first sample in the figure?
2 Which sample in the figure is stored with the lowest code? Give its code.
3 A sound is sampled at 8 kHz for 2 seconds. How many samples are taken?
4 The sampling resolution is 5 bits. How many amplitude levels are there?
- 11100
- 2sample 7: 0010
- 38000 × 2 = 16 000
- 42⁵ = 32
Sampling rate and resolution
Record the same song twice and one copy can sound crisp and take far more space than the other. Two settings make the difference: the sampling rate is how many samples are taken each second; the sampling resolution is how many bits hold each sample.
Two settings decide how true a recording sounds and how big its file is. The sampling rate is how many samples are taken each second; the sampling resolution is how many bits hold each sample.
Each graph changes one setting from the baseline: count the samples along the time axis, then the levels up the side.
Effects of changing the settings
Better sound always costs more bits, and the reason says where those bits come from. Be able to link each change to its effect on accuracy and on file size, with the reason.
| Change | Accuracy | File size |
|---|---|---|
| increase the sampling rate | more samples per second, so the gaps between them are shorter and the digital wave follows the analogue wave more closely | more samples per second are stored |
| increase the sampling resolution | more amplitude levels, so each sample is stored nearer its true amplitude: the quantisation error is smaller | more bits are stored for every sample |
| decrease the sampling resolution | fewer amplitude levels, so a sample may lie further from its true amplitude: quantisation error increases | fewer bits for every sample: smaller file |
| increase the length of the recording | unchanged | more samples in total |
To size a file, multiply the three settings, then weigh what the extra bits cost:
Worked example
Consequences of a larger file
- More data means it takes longer to send over a network.
- It uses up storage faster, so a device holds fewer recordings.
- At the same rate, resolution and duration, stereo doubles the raw size: two channels.
Check the units: a resolution of 2 bytes is 16 bits per sample.
1 A mono recording is sampled at 8 kHz with 8 bits per sample for 10 seconds. What is its size in bytes?
2 The sampling resolution goes from 2 bits to 3 bits. How many amplitude levels are there before and after?
3 The recording in question 1 is made in stereo instead. What is its size now?
4 Why does a higher sampling rate make the file larger?
- 18000 × 8 × 10 = 640 000 bits ÷ 8 = 80 000 bytes
- 22² = 4 levels, then 2³ = 8 levels
- 3two channels: 160 000 bytes
- 4more samples are taken each second, and every sample is stored
Compression: lossy and lossless
Big files are slow to send and soon fill a disk. Compression reduces the size of a file, in one of two ways: keep every detail, or throw some away. The choice depends on whether lost detail would matter, and on how much storage or bandwidth it saves.
Why compress?
A compressed file has fewer bytes, so:
- it needs less storage;
- it uses less bandwidth, so it uploads and downloads sooner and a stream buffers less;
- it uses less of a mobile data allowance;
- it can fit under a size limit, e.g. for an email attachment.
Lossless
No data is lost: decompressing rebuilds the original exactly.
For text, program files and data where every bit matters, or an image that must keep every detail.
Lossy
Data is permanently removed: the original cannot be rebuilt exactly. The file is usually smaller than with lossless.
For sound, images and video where some loss of detail is not noticed.
What comes back after decompressing
Follow each row of pixels through compress and decompress, then compare what comes back with what went in.
Justify a method in context
The same photo may need lossless compression for one job and lossy for another. Be able to choose a method for a scenario and give a reason linked to it.
| Scenario | Choose | Linked reason |
|---|---|---|
| A text file or program | lossless | one lost character changes a word or a value, and the file may no longer open: it is corrupted |
| A live football match sent to phones on mobile data | lossy | far fewer bytes each second, so the picture keeps moving on a slow connection |
| The archive copy of a band’s studio recording | lossless | it will be edited again later, so the original must be rebuilt exactly, every time |
| Music for a website | lossy | smaller files download faster; sound outside human hearing can be removed |
| An X-ray image for a doctor | lossless | every detail must remain for an accurate diagnosis |
- Decide from the scenario, not the file type.
- Lossless when every detail must stay and the bandwidth allows it.
- Lossy when saving storage or bandwidth matters more and the loss goes unnoticed.
- If an uncompressed video already fits a fast, dedicated connection, compression may not be needed: the bandwidth can carry it without delay.
1 A teacher emails a spreadsheet of exam marks. Lossy or lossless? Give a linked reason.
2 A video call runs on a weak phone signal. Lossy or lossless? Give a linked reason.
3 An online shop shows small photos of its products. Lossy or lossless? Give a linked reason.
4 Give two reasons to compress a file before uploading it.
- 1lossless: one changed digit would give a pupil the wrong mark, so every value must come back exactly
- 2lossy: far fewer bytes each second, so the call keeps up on the weak signal; small losses go unnoticed
- 3lossy: smaller photos load faster for shoppers, and the lost detail is not noticed at that size
- 4any two: it uploads sooner; it uses less bandwidth; it uses less storage; it fits a size limit
Compressing text, images and sound
A strip of clear sky in a picture can be hundreds of identical blue pixels. Run-length encoding (RLE) is lossless. It finds runs of consecutive equal values and stores each run as one copy of the value and a count.
One row of pixels stored as runs
Text is stored in runs the same way, and runs can also make a file bigger:
Text
AAAAABBBCCCCCCCC (16 characters) → 5A 3B 8C: 6 values.
When RLE makes a file bigger
With no consecutive repeats, RGB becomes 1R 1G 1B: six stored values rather than three, if counts and colour codes use equal space.
Compressing each type of file
What can safely go depends on the file: one lost letter spoils a text file, while a lost tone in music may go unheard. Be able to give a method for each type of file and say whether it is lossy or lossless.
| File type | How it can be compressed |
|---|---|
| Text | Lossless: RLE stores a run of one repeated character as a single copy and a count; or common words and letter groups are given shorter codes |
| Bitmap image | Lossless: RLE on runs of same-coloured pixels. Lossy: lower the resolution or the colour depth, or merge colours that look alike |
| Vector graphic | A short drawing list has little repeated data, so there may be little to compress; stored as markup (SVG) it can be compressed losslessly |
| Sound | Lossy: lower the sampling rate; lower the sampling resolution; drop frequencies people cannot hear. Lossless: use fewer bits per sample for the amplitude range the recording uses, without changing the samples; store each sample’s difference from the last; RLE on repeated samples |
1 Use RLE to encode the row of pixels GGGGRRBBBBBB.
2 Decode the RLE data 3W 2B 1W.
3 A row of 5 pixels has no two neighbours the same colour. How many values does RLE store for it?
4 Give one lossy method and one lossless method for compressing sound.
- 14G 2R 6B
- 2WWWBBW
- 310: a count and a colour for each pixel, twice the original 5
- 4lossy: lower the sampling rate or resolution, or drop frequencies people cannot hear; lossless: store each sample’s difference from the last