2 - Data Representation
2 - Data Representation
net
2 – Data Representation
Contents
1) Units of information
In this section you will learn about bits, nibbles, bytes, kilobytes, megabytes,
gigabytes, terabytes and petabytes.
When bits are joined together as a bit pattern, they can represent data or
instructions.
A byte is a group of 8 bits. A byte is the smallest bit pattern that can be used to
represent data in a computer system.
Example – byte
Here is a byte:
10100010
Nibbles
A nibble is 4 bits or half a byte. Nibbles are useful when representing numbers
using hexadecimal because each hexadecimal digit represents a nibble. Two
hexadecimal digits together represent a byte.
Quantities of bytes
Measurements are often recorded using the International System of Units, known
as SI units. Multiples of 1,000 bytes can be represented using SI units as follows:
This is for information only. You do not need to learn these terms.
Questions – follow me
1) Explain why computers use bits as a unit of data. [2]
2) Number bases
A number base defines how many unique digits are used within a number system.
Denary (base 10) has 10 unique digits, binary (base 2) has 2 unique digits and
hexadecimal (base 16) has 16 unique digits.
0 1 2 3 4 5 6 7 8 9
A single digit number will only use one of the digits from zero to nine. When we use
a combination of more than one digit, we start to multiply by 10, 100, 1000 etc.
Notice how the power represents the number of zeros in the denary number.
100 means 10 to the power of zero which means multiply by 1 only. 5 x 100 = 5
839 = 8 x 102
+ 3 x 101
+ 9 x 100
If you start from 0 (zero) then the power represents the position in the number:
Number 8 3 9 (839)
Power 2 1 0
8 x 102 3 x 101 9 x 100 (800 + 30 + 9)
Multiple 100s 10s Units (1s)
8 x 100 3 x 10 9x1 (800 + 30 + 9)
5 2 3 7
x x x x
1000 100 10 1
5000 + 200 + 30 + 7 = 5 237
Binary (base 2)
Video
Watch http://tiny.cc/whybinary from code.org about why computers use binary.
The number system used by computers is binary (base 2). This is because there are
only two unique digits which reduces the chances of data corruption:
0 and 1
Each digit in binary is known as a bit – a binary digit. Computers use electrical
switches that can either be on or off. On is represented by 1 (one) and off is
represented by 0 (zero). Bits can be combined to form a bit pattern. All data in a
computer is represented using bit patterns; a bit pattern could represent many
different things including an image, a sound, text or a number. A bit pattern that
represents a number is called a binary number.
1 x 23 = 8 1 x 24 = 16 1 x 25 = 32 1 x 26 = 64 1 x 27 = 128
Here is the binary line which shows the powers of 2 and the denary values:
Power 27 26 25 24 23 22 21 20
Denary 128 64 32 16 8 4 2 1
1 0 1 1 = 1 x 23
+ 0 x 22
+ 1 x 21
+ 1 x 20
If you start from 0 (zero) then the power represents the position in the number:
Number 1 0 1 1 (1011)
Power 3 2 1 0
1 x 23 0 x 22 1 x 21 1 x 20 (8 + 0 + 2 + 1)
Multiple 8 4 2 1
1x8 0x4 1x2 1 x 1 (8 + 0 + 2 + 1)
Denary equivalent = 8 + 0 + 2 + 1 = 11
Video
Watch http://tiny.cc/khannumbers from Khan Academy about number bases.
0 1 2 3 4 5 6 7 8 9 A B C D E F
Each hexadecimal digit can be used to represent a 4-bit binary number (nibble).
The table below shows the equivalent denary, binary and hexadecimal values:
You will often see hexadecimal values used to represent colours. Each pair of
hexadecimal digits represents each colour RED, GREEN and BLUE which each
have values from 0 to 255 or 0 to FF. This is just one way of using hexadecimal.
Video
Watch http://tiny.cc/khanhex from Khan Academy.
Questions – follow me
1) State the names of the number systems of each of the following number bases:
a) Base 2 [3]
b) Base 10
c) Base 16
2) State the name of the number systems used in each of the following numbers
(some can have more than one answer): [5]
a) F4
b) 94
c) 1010
d) 11
e) 3B
3) Use the table on page 4 to lookup the hexadecimal values for each of the
following binary bit patterns: [3]
a) 1011
b) 0000
c) 1110
4) Explain why computers use the binary number system instead of denary. [2]
5) Explain why the hexadecimal number system is used in computer science. [2]
Denary: 255
Binary: 1111 1111
Hexadecimal: FF
Power 27 26 25 24 23 22 21 20
Denary 128 64 32 16 8 4 2 1
Tip: Write out the binary line as soon as your exam starts. All you need to
remember is that 20 = 1 and 27 = 128. You can then fill in the gaps.
1 0 1 1
x x x x
8 4 2 1
8 + 0 + 2 + 1 = 11
1 1 0 1 1 0 1 1
x x x x x x x x
128 64 32 16 8 4 2 1
128 + 64 + 0 + 16 + 8 + 0 + 2 + 1 = 219
Use the random number generator to convert more binary numbers to denary.
0 1 2 3 4 5 6 7 8 9 A B C D E F
When converting to denary, the first 10 digits (0 – 9) are the same as hexadecimal:
Hexadecimal 0 1 2 3 4 5 6 7 8 9
Denary 0 1 2 3 4 5 6 7 8 9
Hexadecimal A B C D E F
Denary 10 11 12 13 14 15
160 means 16 to the power of zero which means multiply by 1 only. 1 x 160 = 1
8B = 8 x 161
+ B x 160
If you start from 0 (zero) then the power represents the position in the number:
Number 8 B
Power 161 160
8 x 161 B x 160 (8 x 16) + (8 x 1)
Multiple 16 1
8 x 16 Bx1 (128 + 11)
Extension: What would the table above look like for the hexadecimal value 7E4A?
Tip: if you know your 8 times table, then you already know your 16 times table –
just double everything – e.g. 4 x 8 = 32 so 4 x 16 = 64. Alternatively write out
the table and fill in 1 x 16 = 16, 10 x 16 = 160. You then know that 5 x 16 = 80
(half of 10 x 16) and you can now fill in 15 x 16 (160 + 80). Now fill in the gaps.
Hex digits: 4 F
Denary digits: 4 15
x x
16 + 1
64 + 15 = 79
Use the random number generator to convert more hex numbers to denary.
1 1 0 1
x x x x
8 4 2 1
8 + 4 + 0 + 1 = 13
Now we have the denary value, we can convert this to hexadecimal by recalling
the tables we used previously:
Hexadecimal 0 1 2 3 4 5 6 7 8 9
Denary 0 1 2 3 4 5 6 7 8 9
Hexadecimal A B C D E F
Denary 10 11 12 13 14 15
1) 1001
2) 1111
3) 0110 1110
4) 0101 0111
5) 0010 0000
Use the random number generator to convert more binary numbers to hex.
1 1 1 1
x x x x
8 4 2 1
8 + 4 + 2 + 1 = 15
The maximum denary value for a 4-bit pattern is 15. To convert a 4-bit pattern to a
denary number, you need to calculate how many 8s, 4s, 2s and 1s there are in the
denary value. You need to divide by 8, then use the remainder to divide by 4,
then use the remainder to divide by 2 and then the remainder to divide by 1.
14 ÷ 8 = 1 remainder 6
6 ÷ 4 = 1 remainder 2
2 ÷ 2 = 1 remainder 0
0÷1=0
A table can be used to help with this method. Below, the original denary number
is divided by 8. The answer is 1 remainder 6. The remainder is then put into the
next column and divided by 4 and this continues.
14 6 2 0
÷ ÷ ÷ ÷
8 4 2 1
1 r6 1 r2 1 r0 0 = 1110
Video
Watch http://tiny.cc/denary2binary from Khan Academy.
Video
Watch http://tiny.cc/largedenarys from Khan Academy and notice how much
more complicated it is to keep dividing by bigger numbers.
As denary values become bigger, this can become rather complicated as you will
have to divide by bigger values such as 32, 64 and 128. There is a much simpler
method which involves repeatedly dividing the denary number by two until it can’t
be divided anymore.
Divide 14 by 2 and you will get a dividend of 7 with a remainder of 0. Keep the
remainder as part of the binary answer and divide the dividend by 2. Keep doing
this until you get a dividend of 0.
Dividend
This can be done with any denary number, including larger denary numbers.
1 0 1 0 1 1 is the same as 0 0 1 0 1 0 1 1.
You could imagine this being the same for denary numbers as 384 is the same as
00384.
1) 5 2) 9 3) 13 4) 15
5) 25 6) 39 7) 58 8) 16
9) 77 10) 135 11) 188 12) 201
13) 128 14) 127 15) 239 16) 255
11110010
1) 5C 2) 3E 3) 25 4) 90
5) A4 6) F9 7) 00 8) E7
Denary 0 1 2 3 4 5 6 7 8 9
Hexadecimal 0 1 2 3 4 5 6 7 8 9
Denary 10 11 12 13 14 15
Hexadecimal A B C D E F
Denary numbers bigger than 15 are slightly more complicated. One way of doing
this is to convert the denary value to binary and then convert the binary value to
hexadecimal.
8B = 8 x 161
+ B x 160
The process is to divide the denary number by 16 and the dividend (answer
without remainder) is what will be used for the first hexadecimal digit. The
remainder will then be used for the second hexadecimal digit.
235 ÷ 16 = 14 remainder 11
(14 x 16 = 224. The remainder left over is 235 – 224 = 11)
Now use the whole number part of the answer (14) and multiply by 16:
Subtract this answer from the original number of 235 to find the remainder:
If you have a scientific calculator then you can calculate the modulus (MOD)
which is also the remainder. Enter 235, then press MOD then enter 16:
Video
Watch http://tiny.cc/dec2hex from Khan Academy.
1) 8 2) 10 3) 15 4) 13
5) 35 6) 176 7) 201 8) 255
Use the random number generator to convert more denary numbers to hex.
Questions – follow me
1) Convert the following binary numbers to denary numbers: [3]
a) 1 1 1 1
b) 0 1 0 1 0 1 0 1
c) 1 0 1 0 1 0 1 0
4) Binary arithmetic
0+0=0
1+0=1
0+1=1
1) 0 0 1 1
+ 0 1 0 0
2) 0 0 0 1
+ 1 0 0 0
3) 0 0 1 1 0 1 0 1
+ 1 0 0 0 0 0 1 0
4) 1 1 0 1 0 0 1 0
+ 0 0 1 0 1 1 0 1
1 0
x x
2 1 Therefore, 1 + 1 is not that simple. It
requires a digit to be carried like in
1 + 0 = 2 denary arithmetic.
2 5 3 3 + 8 = 1 1.
+ 4 4 8
1 1 is written in the units column
1 and 1 is carried.
2 5 3 5 + 4 + 1 = 1 0.
+ 4 4 8
0 1 0 is written in the tens column and
1 1 1 is carried.
2 5 3 2 + 4 + 1 = 7.
+ 4 4 8
7 0 1 7 is written in the hundreds column.
1 1
When denary numbers are added, the maximum digit in a column is 9. The next
number is 10 (ten) and so 0 is put in the column with 1 (one) carried to the next
column.
Binary works the same way. The maximum digit in a column is 1. The next number
is 1 0 (one zero) and so if a column adds up to 1 0 (one zero) a 0 (zero) is put in the
column with 1 (one) carried to the next column.
1 0 1 0 + 0 + 1 = 1.
+ 0 0 1
1 0 1 is written in the twos column.
1
1 0 1 1+0=1
0 0 1
+ 1 1 0 1 is written in the fours column.
Video
Watch http://tiny.cc/binaryadd from Khan Academy.
0 1 1 0 + 1 + 1 = 1 0 (one zero).
+ 1 1 1
1 0 1 0 0 is written in the fours column
1 1 and 1 is carried.
1) 0 0 1 1 0 0 0 1
+ 0 0 1 0 0 1 1 0
2) 0 0 1 1 1 0 0 1
+ 1 0 1 1 0 1 0 1
3) 0 0 1 1 0 1 0 1
+ 1 0 1 1 0 1 1 1
4) 0 1 1 1 1 0 1 1
+ 0 0 1 0 1 1 0 1
5) 0 0 1 1 1 1 1 1
+ 1 0 1 1 1 1 1 1
Extension: Use the adding binary numbers 3 worksheet to add 3 binary numbers.
Extension: Use the random number generator to add more binary numbers.
You can check your answers by converting the binary numbers to denary.
© paullong.net 2020 Page 23 of 54 by Paul Long
The Ultimate GCSE CS textbook for OCR – Chapter 2 Published by paullong.net
Overflow errors
Imagine you had a field in a database that stored the year in two-digit format (eg
18 instead of 2018). Imagine what would happen when adding one to the year
99:
99 + 1 = ?
Is the answer 100, 00 or something else?
A similar problem happens when adding numbers in binary. The largest number
that can be represented by a byte is 255. If only one byte is used for storing
numbers, then an overflow error can occur if binary numbers are added together
resulting in a total bigger than 255. Overflow occurs if there is a carry from the MSB.
Power 27 26 25 24 23 22 21 20
Denary 128 64 32 16 8 4 2 1
MSB = most significant bit (the bit that represents the largest value)
LSB = least significant bit (the bit that represents the smallest value – one)
The MSB is always on the left and the LSB is always on the right.
0 1 1 1 1 1 1 1 1 + 1 = 1 0 (one zero)
+ 1 1 0 0 0 0 0 0
0 1 1 1 1 1 1 0 is written in the column and 1 carried
1
0 1 1 1 1 1 1 1 0 + 1 + 1 = 1 0 (one zero)
+ 1 1 0 0 0 0 0 0
0 0 1 1 1 1 1 1 0 is written in the column and 1 carried
1 1
Now there is a problem. The answer needs to include the 1 that was carried from
the MSB. However, this would require a 9th bit. As only a byte has been allocated,
only 8 bits are available and so there is an overflow error. A value of 256 is missing
from the answer in this example.
© paullong.net 2020 Page 24 of 54 by Paul Long
The Ultimate GCSE CS textbook for OCR – Chapter 2 Published by paullong.net
Binary shifts
Binary shifts are used for multiplication and division.
Binary multiplication
To multiply an integer by 100, you shift the number twice to the left and put 2 zeros
at the end:
5 x 100 = 500
To multiply an integer by 10000, you shift the number 3 places to the left and put 3
zeros at the end:
5 x 1000 = 5000
In denary (base 10), you would shift to the left and add zeros when multiplying
integers by 10, 100, 1000.
In binary (base 2), you shift to the left and add zeros when multiplying by 2, 4, 8.
This only applies to binary integers.
11x2=110 (check: 3 x 2 = 6)
To multiply a binary number by 4, put two zeros at the end of the number:
To multiply a binary number by 8, put three zeros at the end of the number:
This is known as the binary shift left because all bits are moved one place to the
left.
Fill the gap on the right with a zero. The zero at the left is lost.
Check: 17 x 2 = 34 32 + 2 = 34
Fill the gaps on the right with zeros. The zeros at the left are lost.
Check: 17 x 4 = 68 64 + 4 = 68
Fill the gaps on the right with zeros. The zeros at the left are lost.
The general rule for a left shift, is add a zero to the right side of the binary number
(just after the LSB) and discard the bit at the left most side of the binary number.
However, this should not be done if the MSB (most significant bit) is a 1 (one) and
there are a limited number of bits available (e.g. one byte) because it would
cause an overflow error.
There are only 8-bits available. What would have been the new MSB representing
256 cannot be fitted into the 8-bit answer.
Extension:
Each answer should be shown in 8-bit binary format (one byte).
The binary line shows us how many places we need to shift by looking at the power
of 2:
Places to shift 27 26 25 24 23 22 21 20
Multiplier 128 64 32 16 8 4 2 1
For example, to multiply or divide by 32, you would shift 5 places.
Check: 34 ÷ 2 = 17 16 + 1 = 17
Note: a binary shift right is an integer/floor division (DIV) rather than a regular
arithmetic division.
Extension:
7) 0001 0011 ÷ 2 8) 1011 1010 ÷ 8
Video
Watch http://tiny.cc/binaryshift from CatComputerTeacher on YouTube.
Questions – follow me
1) State the purpose of a binary shift right? [1]
3) State why might you perform a binary shift of 3 places to the left. [1]
4) State why might you perform a binary shift of 2 places to the right. [1]
5) a) Add together the following two 8-bit binary numbers. Express your
response in an 8-bit binary form. [2]
0 1 1 0 0 0 1 1
+ 1 0 1 1 1 1 0 0
5) a) Perform a two place right shift on the binary number 11001010. [1]
b) Explain the effect of performing this right shift. [2]
5) Character sets
Computers only work with binary bits. Therefore, all characters need to be
represented by a binary number. A character set is the set of possible characters
that can be represented by a computer system.
ASCII
The American Standard Code for Information Interchange (ASCII) is a set of bit
patterns used for standard characters and control codes. In order that all
applications can understand the data being used, a standard set of character
codes must be used.
7-bit ASCII is the original character set that was adopted internationally and only
uses 7 bits. This means the number of unique codes is limited to 128 and 32 of
these are control codes which means only 96 characters. This was then extended
to 8-bit ASCII to allow for foreign characters. Therefore, there are 256 codes from 0
to 255 (denary) or from 0000 0000 to 1111 1111 (binary).
Note: the term “extended ASCII” will not be tested in an OCR exam, but all ASCII
codes will be represented using 8-bit binary
What are the denary and binary codes for the following characters and controls?
1) 8 2) P (upper) 3) q (lower) 4) * 5) [Carriage Return]
What are the characters or controls represented by the following denary / binary
codes?
6) 27 7) 85 8) 0100 0100 9) 0011 0001 10) 0000 0100
© paullong.net 2020 Page 30 of 54 by Paul Long
The Ultimate GCSE CS textbook for OCR – Chapter 2 Published by paullong.net
Sequential codes
Character codes appear in sequence. This means they are in order. Numbers run
from 0 to 9 and letters run from A to Z and a to z. Therefore, it is possible to work
out a character code if a similar character code is already known.
From this, you can work out that the number 4 will have the next ASCII code after
the number 3 which will be 52 (51 + 1). You can also work out that G will have the
next ASCII code after F which will be 47 (46 + 1).
To work out further codes, draw a small table. For example, to work out the code
for the character y:
Without using a full ASCII table, work out the denary and binary codes for the
following characters:
1) 2 2) 9 3) t 4) g 5) R 6) B
Without using a full ASCII table, work out the characters for the following character
codes:
7) 49 8) 0011 1001 9) 73 10) 0101 1000 11) 109 12) 0110 0001
Extension: write out the sentence represented by these ASCII binary codes:
01010111 01101111 01110111 00100001 00100000 00100000 01010100 01101000
01100001 01110100 00100000 01110111 01100001 01110011 00100000 01101000
01100001 01110010 01100100 00101110
Unicode
Extended ASCII had many variants and there were still only 256 characters
available. A new character set emerged.
Unicode includes a lot more characters including a wider range of symbols and
characters for many different alphabets.
The first 128 characters (codes 0 to 127) of Unicode are the same as 7-bit ASCII.
After that, Unicode has its own set of codes. For example, character codes 880 to
1023 are Greek characters.
As there are many thousands of Unicode characters, they are usually shown as
hexadecimal codes rather than binary codes.
Activity - Unicode
Search the World Wide Web for a Unicode table. What are the characters
represented by the following codes?
Unicode has many variations, but the UTF-32 version uses four bytes for each
character. This gives over 4 million possible characters (232)
The size of a text file is calculated by multiplying the number of bits per character
by the number of characters:
file size (bits) = bits per character x number of characters
Questions – follow me
1) Define the term character set. [1]
4) The ASCII denary code for T is 84. What is the ASCII denary code for Q? [1]
5) The Unicode code for g is 0110 0111. What is the Unicode code for h? Show
your working [2]
6) Give two reasons why Unicode might be used instead of ASCII. [2]
© paullong.net 2020 Page 33 of 54 by Paul Long
The Ultimate GCSE CS textbook for OCR – Chapter 2 Published by paullong.net
6) Representing images
Pixels can be used to represent images. A pixel is short for picture element and is a
single point in an image.
This low quality image of Pacman ghosts shows how images are made from pixels:
Can you work out approximately how many pixels there are horizontally and
vertically?
Images are displayed as a set of pixels which form together to make an image.
Visual Display Units (VDUs / monitors) display images using pixels. A true high
definition monitor will have 1920 pixels in width and 1080 pixels in height. This works
out at a total of approximately 2 million pixels (2,073,600).
© paullong.net 2020 Page 34 of 54 by Paul Long
The Ultimate GCSE CS textbook for OCR – Chapter 2 Published by paullong.net
The higher the number of pixels for the same image, the better quality an image
will be. This is because there are more pixels which appear smaller and cannot be
seen and so the ‘blocky’ pixelated effect is not noticed by the human eye. More
pixels can also be used to create the image.
Video
Watch the Pixels movie trailer at http://tiny.cc/pixels
Notice how some images are pixelated and the pixels can be clearly seen.
Bitmaps
A bitmap is an image formed from pixels.
Bitmap size
The size in pixels of a bitmap is calculated by multiplying the width of the image in
pixels by the height of the image in pixels:
Note: this is often misconceived as the image resolution. Resolution can have
different meanings for images, cameras, screens and printing.
1) 2)
Colour depth
The colour depth is the number of bits (binary digits) used to represent each pixel.
A black and white image has 2 colours and therefore only needs a single bit to
represent white as 1 (one) and black as 0 (zero). A black and white image
therefore has a colour depth of 1 (one) because it only uses 1 bit.
00 or 01 or 10 or 11
More bits means a higher colour depth and that means more colours can be used.
These are the number of colours that can be achieved with each colour depth:
White = 00
Red = 01
Yellow = 10
Black = 11
The bit pattern for the whole image can be worked out by substituting each colour
with its 2-bit pattern:
Starting with the bottom row, the binary representation would be:
0111 0000 1010 0011
0111 0000 1010 0011 1010 1001 0101 1101 1101 1001
1010 0011
© paullong.net 2020 Page 38 of 54 by Paul Long
The Ultimate GCSE CS textbook for OCR – Chapter 2 Published by paullong.net
This is the process the computer follows when storing a black and white bitmap.
Watch the video at http://tiny.cc/bwvideo and then use the pixelation widget at
http://tiny.cc/bwpuzzle to change the dimensions and create an image.
Metadata
Meta data is data about data. For a file, metadata can include:
• type of file (eg bitmap)
• file size (eg 3 Mb)
• date created (eg 20-12-2017)
Use http://tiny.cc/meta-data to find out what meta data is stored about some of
your images.
Increasing the width, height or colour depth will increase the file size. Files can
therefore be kept smaller by not having lots of spare white pixels and only using
the necessary number of colours for the colour depth.
This image has lots of unnecessary white pixels around the edge. Its size in pixels
can be reduced from 128 to 36 by removing the unnecessary white pixels:
Width = 6
Height = 6
Size in pixels = 6 x 6 = 36
If the image above had a colour depth of 8 then that would allow for 256 colours.
This could be reduced to a colour depth of 1 (one) to keep the file size smaller.
Note: The size of the file will also include metadata, but at GCSE level you only
need to calculate the storage space needed for the pixel data.
Size (b) = W x H x D
Size (b) = W x H x D
Size (b) = 28 x 45 x 8
When data is stored, it is often measured in bytes. You may recall from earlier in
this chapter that there are 8 bits in a byte.
Size (B) = W x H x D ÷ 8
Size (B) = W x H x D ÷ 8
Size (B) = 32 x 15 x 16 ÷ 8
1) A bitmap that is 10 pixels high, 1 pixel wide and has a colour depth of 4.
3) A bitmap that is 600 pixels wide, 400 pixels high and has a colour depth of 16.
Note: the method that has been used at GCSE is known as an indexed bitmap
because each pixel is represented by a bitmap pattern that directly
represents a colour. Photographs tend to be represented using values for
RGB (red, green, blue). Watch the video below for more information, but
you do not need to know this for the exam.
Extension video
Watch http://tiny.cc/rgb-bitmap to find out how photographs are stored using the
RGB method. Notice how 3 channels of one byte each gives a colour depth of 24.
Questions – follow me
1) What is a pixel? [1]
3) A bitmap image is 21 pixels high and 3 pixels wide. How many pixels are in the
image? [1]
a) Calculate the minimum file size of this image. Show your working. [4]
b) Explain why the actual file size is slightly more than you have calculated.
[2]
6) Charlie has produced an image. Part of the bitmap image is shown below
with each letter representing a colour:
B B W R Y
B B W R R
B W W R R
Y B B R R
Y Y B W W
Using the example shown above, explain how a bitmap image is stored on a
computer. [5]
7) Representing sound
Sampling
Sound begins life in an analogue format. This means it has no discrete (exact)
value and varies continuously. It can be represented in the form of a wave as
shown below:
Equilibrium
As time passes (horizontal x-axis) the sound changes amplitude, which is the
distance from the equilibrium (middle) position.
Video
Watch the sound waves change in this music video. Notice how the distance from
the equilibrium (amplitude) is greater when the sound is louder.
The samples will be taken thousands of times per second. The more samples that
are taken, then the higher quality the digital sound will be because more
measurements of the sound are taken. The number of samples taken per second
is known as the sample rate which is measured in hertz (Hz). Each sample will be
stored using binary.
Video
Watch http://tiny.cc/samplerate for an overview of sample rate and to hear the
effect of the sample rate on sound.
Example - sampling
11
10
9
8
7
6
5
4
3
Amplitude
2
1
0
-1 0 1 2 3 4 5 6 7 8 9 10
-2
-3
-4
-5
-6
-7
-8
-9
-10
-11
Time (milliseconds)
For this analogue sound, a sample will be taken from the analogue electrical
signal every millisecond. This is a sample rate of 1 kHz (1,000 samples per second).
At 4 milliseconds, the sample taken is an amplitude of 6 and at 7 milliseconds it is -
4.
Time (ms) 1 2 3 4 5 6 7 8 9 10
Amplitude 10 -4 0 6 6.5 0 -4 5 3 -1
The digital sound is shown in orange in the graph below. As you can see, some of
the sound is missed out. This is why it is important to have a high enough sample
rate to maintain the original quality.
11
9
7
5
3
Amplitude
1
-1 0 1 2 3 4 5 6 7 8 9 10
-3
-5
-7
-9
-11
Time (milliseconds)
Video
Watch http://tiny.cc/bitdepth to hear the effect of the bit depth on the dynamic
range of an audio recording.
6
Amplitude
0
0 1 2 3 4 5 6 7 8 9 10
-3
-6
-9
Time (milliseconds)
Video
Watch http://tiny.cc/quantizing for a summary of sample rate and how quantizing
is used to give the bit depth.
For a single channel of sound, the bit rate of a sound file is calculated as:
The formula for calculating the size of a single channel sound file is:
Note: a sound file will also include some metadata which requires a small amount
of storage.
© paullong.net 2020 Page 47 of 54 by Paul Long
The Ultimate GCSE CS textbook for OCR – Chapter 2 Published by paullong.net
Video
Watch Digital Audio Explained at http://tiny.cc/audioexplained for an explanation
of the terms used during this section.
1) A 20 second telephone call recorded with a sample rate of 8,000 Hz and a bit
depth of 8.
2) A 45 second music file that has a sample rate of 22 kHz and a bit depth of 16.
3) A 3 minute CD track that has a sample rate of 44.1 kHz and a bit depth of 16.
4) A 4.5 minute music file that has a sample rate of 11,025 Hz and a bit depth of
4.
5) A 3 minute 40 second voice recording that has a sample rate of 16,000 Hz and
a bit depth of 8.
Extension: calculate each of the above in bytes and then calculate in kB or MB.
Note: a sound file will often include more than one channel of sound; to
calculate the file size of a sound file with more than one channel, simply
multiply your answers by the number of channels:
Questions – follow me
1) Explain why sound needs to be converted to a digital format. [2]
5) a) Which one of the following is true if you increase the bit depth?
A) File size reduces
B) Sound quality reduces
C) Sound quality increases
D) Sample rate increases [1]
b) Which one of the following is true if you increase the sample rate?
A) File size reduces
B) Sound quality reduces
C) Bit depth increases
D) Bit rate increases [1]
6) a) Explain why a high quality sound file needs a high sample rate. [2]
b) Explain why a high quality sound file needs a high bit depth. [2]
John reduces the bit depth used to store his recorded song.
b) Explain two effects this will have on his recorded song. [4]
8) Data compression
Video
Watch this explanation of file compression http://tiny.cc/compressionbbc from
BBC Bitesize.
File sizes can get quite large, particularly if they contain images, sound or video.
When storage space is limited, it is useful to be able to reduce the size of files so
that more can be fitted on to the storage medium. Compression is reducing the
number of bits needed to store data.
1 2 3 4 5 6 7
Imagine you have a USB flash memory stick and you want to store some videos of
you and your friends. If each video uses up 4 GB of storage and you have 10
videos then you will need 40 GB of space. If your memory stick is only 16 GB in size
then you will only be able to store 4 of the videos. However, if the videos have
been compressed to 1.5 GB each then you can store all 10 of them on a 16 GB
USB memory stick.
It’s also good to compress files for use on the Internet. When transferring large files
it takes a long time, but if they are compressed in size then they can be transferred
more quickly. Imagine you are trying to view the BBC website on a slow 3G mobile
connection. It can take ages to open the page. Now imagine what it would be
like if the images on the website weren’t already compressed – it would take even
longer.
You may also have experienced occasions when you have sent an email with a
large attachment but it cannot be received at the other end. This is because the
recipient has a file size restriction on their inbox. Compressing the file might make it
small enough to be allowed to be received.
Types of compression
There are two categories of compression. Lossy and lossless. Lossy compression
means that parts of a data file are lost when the file is made smaller. This could be
by reducing the number of pixels in an image, or reducing the bit depth of a
sound file or reducing the sample rate. Once those bits of data have been
removed, they cannot be retrieved.
The image is no longer as high quality as much of the data has been lost.
The trick with lossy compression is to reduce the file size by removing aspects that a
human cannot see or hear and so make no difference to a person.
Lossless compression reduces a file’s size without losing any data. There are many
methods that can be used including grouping data together.
Video
Watch this http://tiny.cc/conveyor (supermarket conveyor belt) analogy of one
method of compression known as run-length coding.
Activity - compression
Watch http://tiny.cc/compressvideo from code.org and then use the text
compression widget from http://tiny.cc/compresspuzzle
Questions – follow me
1) Contrast lossy and lossless compression. [2]
3) John has recorded himself singing. He needs to send the recording and the
lyrics (words of the song) by email to his music teacher.
a) Explain why lossy compression is suitable for the sound recording. [2]
b) Explain why lossy compression is not suitable for the lyrics. [2]