Year 10 · Computer Science · Autumn 1

Data representation · Lesson 4 of 5

Text, images and sound as bits

Theory1.2 Text, sound and images1.3 Data storage and compression

Year 10 · Computer Science · Data representation · Lesson 4 of 5

You will learn to

  • Explain how a character set, such as ASCII or Unicode, turns text into binary.
  • Compare ASCII and Unicode, including why Unicode files are usually larger.
  • Describe how resolution, colour depth, sample rate and sample resolution affect quality and file size.
  • Calculate the file size of an image and of a sound file, with units on every line.

Year 10 · Computer Science · Data representation · Lesson 4 of 5

Success criteria

You have got it when you can say:

  • I can say why Unicode can show more languages than ASCII.
  • I can explain what happens to quality and file size when the sample rate goes up.
  • I can work out that a 1024 × 768 image with 24-bit colour is 2.25 MiB.
  • I can work out the size of a sound file from its sample rate, resolution and length.

Year 10 · Computer Science · Data representation · Lesson 4 of 5

Retrieval starter

Questions from before. Write your answers, then show them.

  1. Last lesson

    A 10 × 10 image at 8 bits per pixel takes…

    A 80 bytesB 800 bits = 100 bytesC 8,000 bits

    B. 800 bits = 100 bytes

  2. Earlier this unit

    How many bits are in a byte?

    A 8B 16C 4

    A. 8

Year 10 · Computer Science · Data representation · Lesson 4 of 5

Key words (1 of 4)

Bit
A single binary digit, 0 or 1.
Nibble
A group of 4 bits, which matches one hexadecimal digit.
Byte
A group of 8 bits.
Denary
The base 10 number system we use every day, with digits 0 to 9.

Year 10 · Computer Science · Data representation · Lesson 4 of 5

Key words (2 of 4)

Binary
The base 2 number system computers use, with digits 0 and 1.
Character set
A list of characters a computer can use, each with its own binary code.
ASCII
A character set using 7 bits per character, giving 128 characters, mainly for English.
Unicode
A character set using more bits per character, covering most world languages, symbols and emojis.

Year 10 · Computer Science · Data representation · Lesson 4 of 5

Key words (3 of 4)

Sample rate
The number of sound samples taken each second, measured in hertz (Hz).
Sample resolution
The number of bits used to store each sound sample.
Pixel
The smallest single-coloured square in a bitmap image.
Image resolution
The number of pixels in an image, often written as width × height.

Year 10 · Computer Science · Data representation · Lesson 4 of 5

Key words (4 of 4)

Colour depth
The number of bits used to store the colour of each pixel.
Lossy compression
Making a file smaller by permanently removing some data.
Lossless compression
Making a file smaller without losing any data, so the original can be rebuilt exactly.
Run-length encoding (RLE)
A lossless method that stores each run of repeated values as a count and the value.

1.2 Text, sound and images · The explanation · step 1 of 16 · part 1 of 2

Character sets

A computer can only store numbers. So every character is given a number code.

A character is any letter, digit, punctuation mark, space or symbol.

A character set is the full list of characters a computer can use, with the binary code for each one.

When you press a key, the keyboard sends the code. The screen looks up the code and draws the character.

1.2 Text, sound and images · The explanation · step 1 of 16 · part 2 of 2

Character sets (continued)

e.g.Example
The word Hello in ASCII: H = 72 = 01001000 e = 101 = 01100101 l = 108 = 01101100 l = 108 = 01101100 o = 111 = 01101111 5 characters × 8 bits = 40 bits
?Why?

Both computers must use the same character set. If they do not, a message arrives as strange symbols.

1.2 Text, sound and images · The explanation · step 2 of 16 · part 1 of 2

ASCII

ASCII (American Standard Code for Information Interchange) uses 7 bits per character. That gives 2⁷ = 128 characters.

It covers English letters, digits, punctuation and some control codes like "new line".

Extended ASCII uses 8 bits, giving 256 characters. The extra ones add some accented letters and symbols.

Codes run in order. A is 65, so B is 66 and C is 67. Lowercase a is 97, which is 32 more than A.

1.2 Text, sound and images · The explanation · step 2 of 16 · part 2 of 2

ASCII (continued)

CharacterDenary codeBinary (8 bits)
A6501000001
C6701000011
a9701100001
0 (the digit)4800110000
space3200100000
!Watch out

The digit 0 is not stored as 00000000. As a character it has the code 48. A digit in text is a character, not a number.

1.2 Text, sound and images · The explanation · step 3 of 16 · part 1 of 3

Unicode

Unicode is a much bigger character set. It can use up to 32 bits (4 bytes) per character.

It has room for over a million characters. It covers almost every written language, maths symbols and emojis.

The first 128 Unicode codes are the same as ASCII, so ASCII text still works.

The cost: Unicode uses more bits per character, so text files can be bigger.

1.2 Text, sound and images · The explanation · step 3 of 16 · part 2 of 3

Unicode (continued)

ASCIIUnicode
Bits per character7 (8 for extended)More: up to 32
Number of characters128 (256 extended)Over a million
LanguagesEnglish onlyAlmost all world languages
Symbols and emojisVery few, no emojisYes, including emojis
File size for the same textSmallerCan be larger

1.2 Text, sound and images · The explanation · step 3 of 16 · part 3 of 3

Unicode (continued)

e.g.Example
Spanish ñ has the Unicode code 241. It is not in 7-bit ASCII at all. The grinning face emoji has the code 1F600 in hex (128,512 in denary). It needs at least 17 bits. A Madrid school website in Spanish, Arabic and Chinese needs Unicode.
?Why?

ASCII was designed for English in the 1960s. The internet joined the whole world, so a far larger set was needed.

1.2 Text, sound and images · The explanation · step 4 of 16

Sound: sampling

Real sound is a wave. It changes smoothly, so it is called analogue.

A computer cannot store a smooth wave. It measures the height (amplitude) of the wave at fixed time gaps.

Each measurement is a sample. Each sample is stored as a binary number.

This is called sampling. The stored samples are a close copy of the wave, not a perfect one.

There is a diagram for this step in the IGCSE library.

1.2 Text, sound and images · The explanation · step 5 of 16 · part 1 of 2

Sample rate and sample resolution

Sample rate is the number of samples taken each second. It is measured in hertz (Hz). 44,100 Hz means 44,100 samples every second.

Sample resolution is the number of bits used to store each sample. 16 bits gives 2¹⁶ = 65,536 possible heights.

A higher sample rate catches quicker changes in the wave. A higher sample resolution measures each height more precisely.

Both make the recording more accurate and closer to the real sound. Both also make the file bigger.

1.2 Text, sound and images · The explanation · step 5 of 16 · part 2 of 2

Sample rate and sample resolution (continued)

RecordingSample rateSample resolutionQuality
Old phone call8,000 Hz8 bits (256 levels)Clear speech, poor music
Music CD44,100 Hz16 bits (65,536 levels)High quality
Studio master96,000 Hz24 bits (16,777,216 levels)Very high, very large files
!Watch out

Do not mix the two up. Rate is how often you measure. Resolution is how precisely you measure each time.

1.2 Text, sound and images · The explanation · step 6 of 16 · part 1 of 2

Images: pixels and resolution

A bitmap image is a grid of tiny squares called pixels (picture elements).

Each pixel is one colour. Each colour is stored as a binary number.

Image resolution is the number of pixels in the image. It is written as width × height, for example 1920 × 1080.

More pixels show more detail, so the image is sharper. But more pixels need more bits, so the file is bigger.

1.2 Text, sound and images · The explanation · step 6 of 16 · part 2 of 2

Images: pixels and resolution (continued)

e.g.Example
A 1920 × 1080 image has 1920 × 1080 = 2,073,600 pixels. A 640 × 480 image has 307,200 pixels. Enlarged to the same size, it looks blocky (pixelated).
?Why?

Each pixel needs its own colour code. Double the pixels and you double the data.

The explanation · 10 more steps

More on the lesson page

The lesson page has the rest of the explanation, step by step:

  • Colour depth
  • Units of data
  • Converting between units
  • Calculating image file size
  • Calculating sound file size
  • Why we compress files
  • Lossy compression
  • Lossless compression
  • Run-length encoding (RLE)
  • RLE: working out the saving

Open the lesson page

Year 10 · Computer Science · Data representation · Lesson 4 of 5

Try it: Type some text

Year 10 · Computer Science · Data representation · Lesson 4 of 5

Try it: Paint pixels

Year 10 · Computer Science · Data representation · Lesson 4 of 5

Try it: Sample a sound wave

Year 10 · Computer Science · Data representation · Lesson 4 of 5

The maths: How big is some text?

Symbols first, then the words, then the equation. Change the numbers.

Year 10 · Computer Science · Data representation · Lesson 4 of 5

The maths: Image file size

Symbols first, then the words, then the equation. Change the numbers.

Year 10 · Computer Science · Data representation · Lesson 4 of 5

The maths: Sound file size

Symbols first, then the words, then the equation. Change the numbers.

Year 10 · Computer Science · Data representation · Lesson 4 of 5

Quick quiz · 1 of 3

Hex B2 in binary is…

  1. A 1011 0100
  2. B 1100 0010
  3. C 1011 0010

C. 1011 0010

B = 11 = 1011 and 2 = 0010. One hex digit is 4 bits.

Year 10 · Computer Science · Data representation · Lesson 4 of 5

Quick quiz · 2 of 3

Adding 11001100 and 01011010 in an 8-bit register gives…

  1. A 11111111
  2. B An overflow error
  3. C 00100110 with no problem

B. An overflow error

The true answer needs 9 bits (100100110). The ninth bit does not fit.

Year 10 · Computer Science · Data representation · Lesson 4 of 5

Quick quiz · 3 of 3

Shifting 00001010 (10) one place left gives…

  1. A 00010100 (20)
  2. B 00000101 (5)
  3. C 00001011 (11)

A. 00010100 (20)

A left shift doubles. 10 becomes 20.

Year 10 · Computer Science · Data representation · Lesson 4 of 5

Exit ticket

Answer on paper before you go. Then check.

  1. In 8-bit two's complement, 11111111 is…

    A −1B 255C −127

    A. −1 The left bit is worth −128. −128 + 127 = −1.

  2. Which of these is lossy?

    A PNGB JPEGC ZIP

    B. JPEG JPEG throws away detail. PNG and ZIP give every bit back.