Data Representation
Binary, hexadecimal, binary addition, and exactly how text, images and sound become numbers. This is the foundation of the whole GCSE course.
Binary and hexadecimal
Binary to denary
Write the place values above the digits and add where there is a 1.
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|
| 1 | 1 | 0 | 1 | 0 | 0 | 1 | 0 |
128 + 64 + 16 + 2 = 210
Denary to binary
Work from the left, asking whether each place value fits. Convert 156:
- 128 fits, leaving 28. Write 1.
- 64 does not fit. Write 0.
- 32 does not fit. Write 0.
- 16 fits, leaving 12. Write 1.
- 8 fits, leaving 4. Write 1.
- 4 fits, leaving 0. Write 1.
- 2 no, 1 no. Write 0, 0.
Result 10011100. Check: 128 + 16 + 8 + 4 = 156.
Hexadecimal
Base 16, using 0 to 9 then A to F.
| Denary | 10 | 11 | 12 | 13 | 14 | 15 |
|---|---|---|---|---|---|---|
| Hex | A | B | C | D | E | F |
Why it is used: one hex digit replaces four binary digits, so values are a quarter of the length and far easier for a person to read, write and remember without mistakes. You see it in colour codes, MAC addresses and error codes.
Converting
Binary to hex: split into nibbles of four bits from the right, convert each.
11010110 becomes 1101 and 0110, which is 13 and 6, so D6.
Hex to binary: expand each digit to four bits.
2F becomes 0010 and 1111, so 00101111.
Hex to denary: multiply the first digit by 16 and add the second.
3A = (3 x 16) + 10 = 58
Number base converter
Convert between denary, binary and hexadecimal, with every step of the working written out. This tool needs JavaScript, so turn it on to use it. Everything you need to answer the exam question is explained in the text above.
- Split the byte into two nibbles of four bits. Colours keep each nibble with its digit.
- Convert each nibble on its own with 8, 4, 2 and 1: 1010 is 10 and 1111 is 15.
- Write each value as one hex digit, 10 as A and 15 as F, and put them side by side.
- Learn the table: 0 to 9 look the same in hex, then A is 10 up to F which is 15.
Binary addition and units
The four rules
0 + 0 = 0 0 + 1 = 1 1 + 1 = 0 carry 1 1 + 1 + 1 = 1 carry 1
Work from right to left, exactly like column addition.
01101010 (106)
- 00110101 (53)
---------- 10011111 (159)
Overflow
An overflow error happens when the answer needs more bits than are available. With 8 bits the largest value is 255, so any total above that overflows, the carry out of the leftmost column is lost, and the stored answer is wrong.
Units
| Unit | Size |
|---|---|
| Bit | One 1 or 0 |
| Nibble | 4 bits |
| Byte | 8 bits |
| Kilobyte | 1000 bytes |
| Megabyte | 1000 KB |
| Gigabyte | 1000 MB |
| Terabyte | 1000 GB |
File size calculator
Work out the size of an image, a sound file or a block of text, one conversion at a time. This tool needs JavaScript, so turn it on to use it. Everything you need to answer the exam question is explained in the text above.
- Adding 1111 1111 and 0000 0001 produces a ninth bit. The register only keeps eight, so the answer shown is 0000 0000.
- An odometer is the same: 999 plus 1 gives 000 because the 1000 does not fit in three wheels.
- The answer is wrong, the carry flag is set to record it, and it is avoided with more bits or a check.
Representing text, images and sound
Text
Every character is given a number, and that number is stored in binary. The agreed list is the character set.
- ASCII uses 7 bits, giving 128 characters. Enough for English.
- Unicode uses 16 bits or more, giving over a million characters, covering every major writing system and emoji.
Unicode's advantage is language coverage. Its cost is file size, because each character takes more bits.
Characters are in order, so if A is 65 then D is 68. The character '5' is not the number 5: its ASCII code is 53.
Images
An image is a grid of pixels, each storing a colour as a binary number.
- Resolution is the number of pixels, written width by height
- Colour depth is the number of bits per pixel, and n bits gives 2n colours
- Metadata is data about the image such as its dimensions, needed so the computer knows how to arrange the pixels
file size in bits = colour depth x width x height
A 500 by 400 image at 8 bit colour depth:
8 x 500 x 400 = 1,600,000 bits = 200,000 bytes = 200 KB
Sound
Sound is a continuous wave, so it must be sampled: measured at regular intervals with each measurement stored as a binary number.
- Sample rate is how many measurements per second, in hertz
- Bit depth is how many bits store each measurement
file size in bits = sample rate x duration in seconds x bit depth
A 60 second clip at 44,100 Hz with 16 bit depth:
44100 x 60 x 16 = 42,336,000 bits = 5,292,000 bytes = about 5.3 MB
Better quality always means more numbers, and more numbers always means a bigger file. There is no way around that trade off.
- A bitmap is a grid of pixels. This one is 8 by 8, so 64 of them.
- Pick one pixel. Its colour is three numbers: red, green and blue.
- Each number is 8 bits, so one pixel costs 24 bits, which is 3 bytes.
- File size = width × height × colour depth. That is the whole formula.
- Each character has a code number, and the computer stores that number in binary.
- The codes run in order, so you can work out C from A. The character 7 is not the number 7.
- More bits per character means more characters: 128, then 256, then over a million.
- The picture is a grid of pixels, stored as one long stream of bits.
- Metadata that must be stored: width, height and colour depth. Without them the bits cannot be turned back into the picture.
- Extra metadata such as date, device and GPS location is useful, but sharing it can be a privacy risk.
Key terms you must be able to define
- Binary
- Base 2, using only the digits 0 and 1.
- Denary
- Base 10, the everyday number system. Also called decimal.
- Hexadecimal
- Base 16, using 0 to 9 and A to F, where one digit represents four bits.
- Overflow
- An error where a result needs more bits than are available, so the stored answer is wrong.
- Character set
- The agreed list of characters and the binary code used for each.
- ASCII
- A 7 bit character set representing 128 characters.
- Unicode
- A character set using 16 or more bits, representing over a million characters.
- Resolution
- The number of pixels in an image, given as width by height.
- Colour depth
- The number of bits used to store the colour of each pixel.
- Sampling
- Measuring a sound wave at regular intervals and storing each measurement in binary.
- Sample rate
- The number of sound samples taken each second, measured in hertz.
Flashcards
Say the definition out loud before you flip the card. Retrieving it from memory is what builds recall, reading it again is not.
Reach the top grade on this topic
This topic is where careful students collect free marks and careless ones give them away.
Write the place values down every time. 128 64 32 16 8 4 2 1. Every single time, even when you are sure.
Check by converting back. It takes ten seconds and catches almost every error.
Show every line of working in calculations, with units. Method marks are real marks, and an answer left in bits when the question asked for kilobytes loses the final mark even when everything else was perfect.
Explain rather than assert. Higher sample rate improves quality because measurements are taken closer together, so the stored data follows the original wave more closely.
- Convert 8 bit binary to denary and back in under 30 seconds
- Convert between binary, hex and denary in both directions
- Add two 8 bit numbers and identify overflow
- Calculate an image or sound file size in the unit requested
Mistakes that cost marks here
- Writing the place values in the wrong direction. The 1 is on the right.
- Splitting binary into nibbles from the left instead of the right.
- Treating hexadecimal A as 1 rather than 10.
- Saying a colour depth of 4 means four colours. It means four bits, so sixteen colours.
- Forgetting to divide by 8 when the answer must be in bytes.
- Forgetting to convert minutes into seconds before a sound calculation.
Hexadecimal exists only for people. The computer never uses it. The colour white in 24 bit binary is twenty four ones in a row, and in hexadecimal it is just FFFFFF, which is why every web developer is grateful for base 16.
Knowledge check
Exam-style questions
Five written questions in the style of the real paper. Write a full answer, then let the marker check it against the mark scheme.
- LUses place values from 128 downwards
- LShows the subtraction working
- LCorrect answer 10111011
Working from the largest place value: 128 fits into 187 leaving 59, so write 1. 64 does not fit into 59, write 0. 32 fits leaving 27, write 1. 16 fits leaving 11, write 1. 8 fits leaving 3, write 0 for 8 being used, so write 1. 4 does not fit into 3, write 0. 2 fits leaving 1, write 1. 1 fits leaving 0, write 1. This gives 10111011, and checking: 128 + 32 + 16 + 8 + 2 + 1 = 187.
- LOne hexadecimal digit represents four binary digits
- LValues are much shorter to write and read
- LShorter values are easier for people to remember and less prone to error
Hexadecimal is used because each hexadecimal digit represents exactly four binary digits, so an eight bit value that needs eight characters in binary needs only two in hexadecimal. Values written in hexadecimal are therefore around a quarter of the length, which makes them far quicker for a person to write down and read back. Because the values are short, people make fewer transcription mistakes and any error that is made is much easier to spot, which is why colour codes, MAC addresses and memory addresses are all normally written in hexadecimal. The computer itself still works entirely in binary.
- LAdds column by column from the right with carries
- LCorrect binary answer 10010000
- LConverts the answer to denary
- LStates that no overflow occurs as the answer fits in 8 bits
Adding column by column from the right and carrying wherever two or three ones meet gives 10010000. Checking in denary, 01011010 is 90 and 00110110 is 54, and 90 plus 54 is 144, which is 10010000 in binary since 128 + 16 = 144. No overflow error occurs, because 144 is within the range 0 to 255 that eight bits can represent, so nothing is carried out of the most significant column and no data is lost.
- LMultiplies colour depth by width by height
- LObtains 23,040,000 bits
- LDivides by 8 to obtain 2,880,000 bytes
- LStates 2.88 MB
File size in bits is colour depth multiplied by width multiplied by height, so 24 x 1200 x 800 = 23,040,000 bits. Dividing by 8 gives 2,880,000 bytes. Dividing by 1000 gives 2880 kilobytes, and dividing by 1000 again gives a file size of 2.88 megabytes.
- LThe amplitude of the sound wave is measured at regular intervals
- LEach measurement is stored as a binary number
- LA higher sample rate means measurements are taken closer together in time
- LSo the recording is a more accurate copy of the original wave, but the file is larger
Sound in the real world is a continuously varying wave, which cannot be stored directly because a computer can only store numbers. Instead the amplitude of the wave is measured at regular fixed intervals, a process called sampling, and each measurement is rounded to the nearest available level and stored as a binary number. Increasing the sample rate means those measurements are taken more often and therefore closer together in time, so less of the wave's shape is missed between samples and the stored data follows the original much more closely, producing a more accurate and better sounding recording. The cost is file size, which is directly proportional to sample rate, so doubling the sample rate doubles the amount of storage the recording needs.