Text, Sound and Images
Everything on a computer — letters, music, photos — is stored as numbers. This is how.
WATCH IT EXPLAINED
EXPLORE IT IN 3D
It's all numbers
A studio desk with a keyboard, a microphone and a camera. Type, record and take photos — and watch every letter, sound and picture become numbers.
Text: every character has a code
A computer stores text by giving every character a number, and storing that number in binary.
A character set is the agreed list of characters and their codes.
The sender and the receiver must use the same character set. If not, the codes come out as the wrong characters.
The codes run in order:
| Character | A | B | … | Z | a |
|---|---|---|---|---|---|
| Code | 65 | 66 | … | 90 | 97 |
The small letters run in order too, from a = 97. So each small letter's code is 32 more than its capital.
Watch out:A digit typed as text is a character too. The character "5" has the code 53, not the value 5.
ASCII
ASCII uses 7 bits per character, enough for English but not for all the world's languages.
ASCII stands for American Standard Code for Information Interchange.
| ASCII | Extended ASCII | |
|---|---|---|
| Bits per character | 7 | 8 |
| Number of codes | 2⁷ = 128, numbered 0 to 127 | 2⁸ = 256 |
| Holds | English letters in both cases, digits, punctuation, the space, some control codes such as a new line | the same, plus 128 more: some accented letters and symbols |
That is enough for English. It is not enough for all the world's languages at once: Mongolian, Chinese and emoji need far more codes.
Remember:n bits give 2ⁿ different codes, because each extra bit doubles the number of patterns.
Unicode
Unicode holds every writing system in use, so it needs more bits per character than ASCII.
Unicode is a character set designed to include every writing system in use, plus symbols and emoji. That is more than 150 000 characters today.
To have room for so many, it needs more bits per character than ASCII: up to 32. So the same text can take up more storage space in Unicode.
Its first 128 codes are the same as ASCII's, so A is still 65.
| Character | Unicode code | In ASCII? |
|---|---|---|
| Ө (Mongolian) | 1256 | no |
| Ү (Mongolian) | 1198 | no |
| 😀 (emoji) | 128 512 | no |
Sound: sampling a wave
To store sound, the computer measures the wave's height again and again, and stores each measurement.
Sound is an analogue wave. Its height, the amplitude, changes smoothly all the time.
To store a sound, the computer measures the wave's amplitude at regular intervals. Each measurement is a sample. It is stored as a binary number.
- A microphone turns the sound into an electrical signal.
- An analogue-to-digital converter (ADC) takes the samples.
- To play it back, a digital-to-analogue converter (DAC) rebuilds a wave from the stored numbers.
- A speaker plays it.
Watch out:Only the samples were stored. Anything the wave did between two samples is lost.
Sample rate and sample resolution
More samples per second, and more bits per sample, give better sound and bigger files.
| Sample rate | Sample resolution | |
|---|---|---|
| What it is | the number of samples taken in a second | the number of bits per sample |
| Measured in | hertz (Hz) | bits |
| Example | 44 100 Hz = 44 100 samples every second | 16 bits give 65 536 levels |
With n bits, each sample can be one of 2ⁿ levels.
A higher sample rate or a higher sample resolution:
- makes the recording more accurate, which means closer to the original wave
- makes the file larger, because more bits are stored
Images: a grid of pixels
A bitmap image is a grid of pixels, and each pixel's colour is stored as a binary number.
A bitmap image is a grid of tiny dots called pixels. Each pixel's colour is stored as a binary number.
With 1 bit per pixel there are only 2 colours: for example, 0 for white and 1 for black. So each row of the picture is just a row of bits.
The resolution of an image is the number of pixels in it, usually given as width × height.
Example:This picture is 8 × 8, so it has 64 pixels. At 1 bit each, it needs 64 bits.
Colour depth
Colour depth is the bits per pixel; n bits give 2ⁿ colours and a bigger file.
Colour depth is the number of bits used to represent each colour, meaning the colour of one pixel.
With n bits per pixel there are 2ⁿ possible colours, not 2 × n.
| Colour depth | Colours |
|---|---|
| 1 bit | 2¹ = 2 |
| 8 bits | 2⁸ = 256 |
| 24 bits: 8 bits each for red, green and blue | 2²⁴ = 16 777 216 |
More bits per pixel give more colours and a more realistic image. But the file grows in proportion: twice the bits per pixel means twice the file size.
Example:This 8 × 8 picture needs 128 bits at a colour depth of 2 bits, and 512 bits at 8 bits.
Resolution
More pixels give a sharper image, but every extra pixel makes the file bigger.
More pixels means more detail. The image looks sharper, and less blocky (pixelated) when it is shown large.
But every pixel needs its own colour value. So more pixels means a bigger file.
Remember:Doubling both the width and the height gives 4 times as many pixels, and a file 4 times as big.
Example:At 8 bits per pixel, this 64 × 64 picture has 4 096 pixels. It needs 32 768 bits, which is 4 096 bytes or 4 KiB.
Lowering the resolution is one way to make an image file smaller: see lossy compression in Data Storage and Compression.
Working out a file size
Multiply to get the size in bits, then divide by 8 and by 1024 to reach the unit asked for.
| File | Size in bits |
|---|---|
| Image | width × height × colour depth |
| Sound | sample rate × sample resolution × length in seconds |
Then:
- Divide by 8 to get bytes.
- Divide by 1024 for kibibytes (KiB).
- Divide by 1024 again for mebibytes (MiB).
Always use 1024, never 1000. Give the answer in the unit the question asks for.
Exam:Write the formula before the numbers. The working can earn marks even when the final answer is wrong.
IMAGE bits = width × height
× colour depth
100 × 100 × 24 = 240 000 bits
÷ 8 = 30 000 bytes
÷ 1024 ≈ 29.30 KiB
SOUND bits = sample rate
× sample resolution
× seconds
44 100 × 16 × 30 = 21 168 000 bits
÷ 8 = 2 646 000 bytes
÷ 1024 ≈ 2 583.98 KiB
÷ 1024 ≈ 2.52 MiB- Width
- 800 pixels
- Height
- 600 pixels
- Colour depth
- 8 bits per pixel
KEY TERMS
CHECK YOURSELF
1.An image is 200 × 100 pixels with a colour depth of 8 bits. What is its size in bytes?
2.What is the effect of INCREASING the sample rate of a sound recording?
3.Why can Unicode represent Mongolian text when ASCII cannot?
4.Text is stored in ASCII. What code is stored for the character "5"?
5.An image has a colour depth of 4 bits. How many different colours can each pixel be?
6.What is the sample resolution of a sound recording?