1.2.4 Data storage
A computer is made of circuits that are either on or off. So it can only store two states. We write these states as 1 (on) and 0 (off). Every number, letter, picture and sound on a computer is stored as a pattern of 1s and 0s.
Numbers
Binary
Denary is the number system you use every day. It has ten digits (0 to 9), and each place is worth 10 times more than the one to its right. Binary has two digits (0 and 1), and each place is worth 2 times more than the one to its right.
In the exam you only work with positive whole numbers up to 8 bits. That means the values 0 to 255.
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|
Binary to denary
Write the place values above the bits. Add up the place values that have a 1 under them.
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|
| 1 | 0 | 1 | 1 | 0 | 1 | 0 | 1 |
Answer: 181
Denary to binary
Work from the left. If the place value fits into what is left, write 1 and subtract it. If it does not fit, write 0.
- 128 fits into 157. Write 1. 157 - 128 = 29.
- 64 does not fit into 29. Write 0.
- 32 does not fit into 29. Write 0.
- 16 fits into 29. Write 1. 29 - 16 = 13.
- 8 fits into 13. Write 1. 13 - 8 = 5.
- 4 fits into 5. Write 1. 5 - 4 = 1.
- 2 does not fit into 1. Write 0.
- 1 fits into 1. Write 1. 1 - 1 = 0.
Answer: 10011101
Check: 128 + 16 + 8 + 4 + 1 = 157.
Adding two binary numbers
Add column by column from the right, as you do in denary. There are only four facts to know:
| Sum | Write | Carry |
|---|---|---|
| 0 + 0 | 0 | none |
| 0 + 1 | 1 | none |
| 1 + 1 | 0 | 1 |
| 1 + 1 + 1 (with a carry) | 1 | 1 |
Working from the right:
- Bit 0: 1 + 0 = 1
- Bit 1: 0 + 1 = 1
- Bit 2: 1 + 1 = 0, carry 1
- Bit 3: 0 + 1 + carry 1 = 0, carry 1
- Bit 4: 1 + 0 + carry 1 = 0, carry 1
- Bit 5: 1 + 0 + carry 1 = 0, carry 1
- Bit 6: 0 + 1 + carry 1 = 0, carry 1
- Bit 7: 0 + 0 + carry 1 = 1
Answer: 10000011
Check in denary: 53 + 78 = 131, and 10000011 = 128 + 2 + 1 = 131.
Overflow
You can see overflow in a binary addition. There is a carry out of the left-hand (most significant) column, and there is no 9th bit to put it in.
- Bit 0: 0 + 1 = 1
- Bit 1: 1 + 1 = 0, carry 1
- Bit 2: 1 + 0 + carry 1 = 0, carry 1
- Bit 3: 0 + 0 + carry 1 = 1
- Bit 4: 1 + 1 = 0, carry 1
- Bit 5: 0 + 1 + carry 1 = 0, carry 1
- Bit 6: 1 + 1 + carry 1 = 1, carry 1
- Bit 7: 1 + 0 + carry 1 = 0, carry 1
The last carry has nowhere to go. The 8-bit answer is 01001001 (73), which is wrong.
Check in denary: 214 + 115 = 329. That is more than 255, so the answer overflows. The true answer is 256 + 73 = 329.
Binary shifts
A binary shift moves every bit to the left or right by a number of places. Gaps are filled with 0s. Bits that move past either end are lost.
- •A left shift moves bits to the left. Each place shifted multiplies the number by 2.
- •A right shift moves bits to the right. Each place shifted divides the number by 2 (the remainder is lost).
Move every bit two places left, drop the two bits that fall off the left end, and add 00 on the right.
00010110 becomes 01011000
Effect: 22 became 88. It was multiplied by 2 twice, so 22 x 4 = 88.
Drop the three bits on the right (100). Add 000 on the left.
10110100 becomes 00010110
Effect: 180 became 22. It was divided by 2 three times, so 180 / 8 = 22.5, and the 0.5 is lost.
Hexadecimal
Hexadecimal (hex) is base 16. It has 16 digits: 0 to 9, then A to F.| Denary | 10 | 11 | 12 | 13 | 14 | 15 |
|---|---|---|---|---|---|---|
| Hex | A | B | C | D | E | F |
In this course hex numbers have two digits (00 to FF). The left digit is worth 16 and the right digit is worth 1.
Hex is used because it is shorter than binary, so it is easier for people to read, write and remember, and there are fewer mistakes. For example, 10110101 is B5. Colour codes and memory addresses are often shown in hex.
| Binary | 0000 | 0001 | 0010 | 0011 | 0100 | 0101 | 0110 | 0111 |
|---|---|---|---|---|---|---|---|---|
| Hex | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| Binary | 1000 | 1001 | 1010 | 1011 | 1100 | 1101 | 1110 | 1111 |
|---|---|---|---|---|---|---|---|---|
| Hex | 8 | 9 | A | B | C | D | E | F |
- 173 / 16 = 10 remainder 13.
- 10 is A. 13 is D.
Answer: AD
Check: 10 x 16 = 160, and 160 + 13 = 173.
- 3 x 16 = 48.
- F is 15.
- 48 + 15 = 63
Split into two groups of 4 bits: 1011 and 0101.
- 1011 = 11 = B
- 0101 = 5
Answer: B5
- 7 = 0111
- C (12) = 1100
Join them: 01111100
Check: 64 + 32 + 16 + 8 + 4 = 124, and 7 x 16 + 12 = 124.
Characters
A computer stores each character (letter, digit, symbol) as a binary number. A character set is the list of all the characters a computer can use, and the binary code given to each one.
ASCII
ASCII is a character set. In the exam, treat ASCII as using 8 bits for each character. With 8 bits you can make 2^8 = 256 different codes, so ASCII can represent 256 characters. That is enough for English letters (capital and lower case), digits, punctuation and some control codes.You do not need to memorise the codes. The question will give you one code, and you work out the others.
D, E, F, G: 'G' is 3 letters after 'D'.
68 + 3 = 71
The order of the codes means a computer can sort words into alphabetical order by comparing numbers.
Unicode
256 characters is not enough for every language, and not enough for symbols and emoji. Unicode is a much larger character set. It uses more bits per character (16 bits or more) so it can represent over a hundred thousand characters, from many languages and writing systems.
| Advantages of Unicode | Disadvantages of Unicode |
|---|---|
| Far more characters, including other languages and emoji | More bits per character, so text files are bigger |
Images
A bitmap image is a grid of tiny squares called pixels (picture elements). Each pixel has one colour. The computer stores a binary colour code for each pixel, and the pixels are stored in order, row by row.
Colour depth
| Colour depth | Number of colours |
|---|---|
| 1 bit | 2 (for example black and white) |
| 2 bits | 4 |
| 8 bits | 256 |
| 24 bits | over 16 million |
Each extra bit doubles the number of colours. A bigger colour depth gives more accurate colours and better quality, but each pixel needs more bits, so the file is bigger.
Resolution
A higher resolution has more pixels, so the image has more detail and looks sharper. But there are more pixels to store, so the file is bigger. A low resolution image looks blocky (pixelated) when it is enlarged.
Metadata
An image file needs metadata so that the computer can rebuild the picture. Examples are the width, the height and the colour depth. Cameras also add the date, the time and the file type.
Sound
Real sound is analogue. It is a smooth, continuous wave. A computer can only store digital data, so the sound must be turned into numbers. This is done by sampling.
- 1.The sound wave is measured at regular, equal intervals of time. Each measurement is a sample.
- 2.The height (amplitude) of the wave at that moment is rounded to the nearest value the computer can store.
- 3.Each value is stored as a binary number.
Sample rate
A higher sample rate gives a closer copy of the original wave, so the sound is better quality. There are more samples to store, so the file is bigger.
Bit depth
A higher bit depth means each sample can be stored more precisely, so the sound is better quality. Each sample uses more bits, so the file is bigger.
Duration
Duration is how long the recording lasts. A longer recording has more samples, so the file is bigger. Duration does not change the quality.| Increase this | Benefit | Cost |
|---|---|---|
| Colour depth | More colours, better quality | Bigger file |
| Resolution | More detail, sharper image | Bigger file |
| Sample rate | Closer to the original sound | Bigger file |
| Bit depth | More precise samples | Bigger file |
Exam technique
- •State and give: a short fact, one mark each. For example, "State what a pixel is."
- •Convert and calculate: show your working. Marks are given for the method, so write the place values, the carries or the shifted bits. State the final answer clearly and keep all 8 bits.
- •Describe: say what happens, in order. For sampling, give the steps.
- •Explain: give a reason as well as a fact. "The file is bigger because each pixel needs more bits."
- •Compare: talk about both things. For example, ASCII and Unicode.
- •Link every change to its effect on both quality and file size.
- •For overflow, say that the result is more than 255 and so does not fit in 8 bits.