CH 1
CH 1
Questions
Chapter 1 1
2
Can you think of three examples of analogue data?
Why is analogue data described as continuous data?
The components that process data in a computer are made up of very small
Data representation logic gates. These gates cannot process analogue data, they can only
process digital data. This data is stored in registers. You can find out more
about logic gates in Chapter 10. Digital data is discrete data that only has two
values, 1 and 0. Any data that we want a computer to process must be
converted into digital data. This type of data is also called binary data.
IN THIS CHAPTER YOU WILL: Number systems
• learn why computers use binary to process data In our daily lives we mostly use a denary number system. This is called a
base-10 number system and uses the digits 0–9. The units in a denary number
• develop an understanding about how binary is used to represent
system are ones, tens, hundreds and thousands. Each time the unit increases
different forms of data, such as text, sound and images
by the power of 10.
• learn to convert between the number systems denary, binary and
For example, the denary number 123 has:
hexadecimal
• learn to add two binary numbers and understand what is meant by
overflow
• learn to perform a binary shift and how this affects the number
• learn to use two’s complement to represent negative binary numbers Computers use a binary number system. This is called a base-2 number
• learn how the file size of data is measured system and uses the digits 0 and 1. The units in a binary number system
increase by the power of 2.
• learn how and why data is compressed.
Any denary values need to be converted to binary values so that they can be
processed by a computer.
GETTING STARTED
SKILLS FOCUS 1.1
Working with a partner, write the words ‘text’, ‘sound’ and ‘image’ on a
piece of paper. Around each word, write words that you can think of that CONVERTING BETWEEN DENARY AND BINARY NUMBERS
are linked to each of the three words. For example, you could write the
The size of a binary number is referred to by the number of bits it has. A 4-
words ‘sound wave’ next to the word ‘sound’.
bit binary number will have 4 values that are either 1 or 0, for example,
1001. An 8-bit binary number will have 8 values that are also either 1 or 0.
Binary values can get very large, some have as many as 64 bits; now that’s
a very big number! You will need to be able to understand binary numbers
that have as many as 16 bits.
DEBUGGING USING HEXADECIMAL
First, focus on converting denary numbers to 4-bit binary. To convert denary
Computer programs are the foundation of computer games. If there is an numbers to 4-bit binary the units that you need to use are 1, 2, 4 and 8. You
error with the program, this can cause unexpected behaviour in the game. can indicate with a 1 or a 0 whether that unit is required. For example, if you
For example, a character may move the wrong way when a button is convert the denary number 13 to a 4-bit binary number you can use the
pressed. The programmer needs to find out why the character is moving following steps:
incorrectly. The amount of code that needs to be assessed to find this Write down the binary units from 8 to 1. An easy way to do this is using a
error in a computer game is enormous and the binary values involved will table.
be vast. Therefore, the programmer will often use hexadecimal to debug
the error. One way this can be done is to look at the address for a 8 4 2 1
variable. The address is the location in memory where the data is stored
and it is shown in hexadecimal. This address is then looked up in a table
to find the value held in the address. The value is also given as Do you notice how the units increase by the power of 2 each time (going
hexadecimal. If the value in the address is, for example, 0000 or FFFF from right to left)?
(this can mean that the variable has not been initiated) the programmer Compare the denary number (13) to the first binary unit (8) to see whether it
will know that there is a problem with this value and has located the is equal to or greater than the denary number. 13 is greater than 8, which
variable with which the error is occurring. The programmer can then find means that the unit 8 is required and you can write a 1 beneath it. 8 can
out why the variable is not holding a valid value. then be subtracted from the denary value, 13 – 8 = 5.
If the addresses and values were given as binary, rather than as
hexadecimal, then it would be more difficult to identify if an error has 8 4 2 1
occurred. For example, it is easier to see if an address contains a valid 1
value, e.g. F2A5, rather than 1111001010100101.
Now compare the denary number (5) to the next binary unit (4) to see
whether it is equal to or greater than the denary number. 5 is greater than 4,
which means that the unit 4 is required and you can write a 1 beneath it. 4
can then be subtracted from the denary value, 5 – 4 = 1.
8 4 2 1
1 1
Then compare the denary number (1) to the next binary unit (2) to see
whether it is equal to or greater than the denary number. 1 is not greater
than 2, which means that the unit 2 is not required and you can write a 0
beneath it. No subtraction is needed this time as you haven’t used the unit.
8 4 2 1
1 1 0
Finally, compare the denary number (1) to the last binary unit (1) to see
Figure 1.1: Data represented by hexadecimal letters and numbers
whether it is equal to or greater than the denary number. 1 is equal to 1,
which means that the unit is required and you can write a 1 beneath it. 1 can
Discussion questions then be subtracted from the denary value. 1 − 1 = 0.
1 Do you think that you have ever seen or used hexadecimal before? If 8 4 2 1
you have, can you provide an example of where you have seen or
used it? 1 1 0 1
2 Why is it important for a programmer to be able to effectively debug a This means that if you convert the denary number 13 to 4-bit binary, you get
computer program? the binary number 1101.
Questions
1 What is the largest denary number that can be created with a 4-bit
binary number?
2 Convert the denary number 6 to a 4-bit binary number.
3 Convert the binary number 9 to a 4-bit binary number.
To convert denary numbers to 8-bit binary the units that you need to use are
1, 2, 4, 8, 16, 32, 64 and 128. You can indicate, again, with a 1 or a 0
whether that unit is required. For example, if you convert the denary number
150 to an 8-bit binary number you can use the same method as before:
Write down the binary units from 128 to 1:
128 64 32 16 8 4 2 1 SKILLS FOCUS 1.2
REFLECTION
How did you know how to add in the correct missing units for Question 8?
How did you work out each unit?
Hexadecimal
Hexadecimal is also a number system. Humans can use hexadecimal, but
computers cannot process it. Like denary numbers, hexadecimal numbers also
need to be converted to binary to be processed by a computer.
Hexadecimal is a base-16 system and uses 16 symbols, these are the
numbers 0–9 and the letters A–F. This is to allow the denary values 0–15 to be
represented in hexadecimal. This is shown in Table 1.1.
Denary 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F
Table 1.1: Hexadecimal representations of denary numbers
The reason for using the symbols A–F for the denary numbers 10–15 is so
only one symbol is needed for the denary number in hexadecimal.
Why is hexadecimal used in computer science?
Questions
Programmers often use hexadecimal when writing and analysing computer
programs. They do this because it is easy for a human to read hexadecimal, 3 Add the 8-bit binary values 00011001 and 01000011.
rather than binary. 4 Add the 8-bit binary values 00100110 and 01010111.
For example, if a programmer looked at a set of data that is stored in registers, You should now know that the largest number that can be stored in an 8-bit
as binary it could look like this: binary register is 255. What happens when two 8-bit binary values are added,
10011100101110111000111011100010111101011010 and the result is larger than 255?
The programmer may be trying to find out if the data stored matches the The following example, which is almost complete, is very much like the
correct data which should be: previous calculation with a slightly different binary number. Can you spot the
difference?
10011100101110111001011011100010111101011010
+ 1 1 1
At a glance, it is difficult to see whether the two values match or if an error has 1 0 0 1 0 1 0 0
occurred. 1 0 0 1 1 1 1 0
If that stored data is represented in hexadecimal it would be: 0 1 1 0 0 1 0
9CBB8EE2F5A If you now try and do the final calculation, that would be 1 + 1 = 10. You write 0
Comparing it to the correct value that should be: in the answer section, but there is nowhere to carry the 1. This is because the
two 8-binary binary values are added the result is 306, which is greater than
9CBB96E2F5A 255. Therefore, the number cannot fit in the 8-bit register and an overflow
It is much easier to see that the data does not match, and the programmer can error is created.
identify that an error has occurred.
The benefits of using hexadecimal rather than binary for a programmer are:
+ 1 0 0 1 0 1 0 0 If a logical shift to the right is performed on the binary number, each value in
0 0 0 1 1 1 1 0 the binary number is moved one place to the right. The result would be:
1 0 0 0 1 0 1 1 0
The next calculation is 1 + 1. Rule 3 means the result is 10. You need to write You should notice that the right most 0 has been removed from the register.
the 0 in the answer section and carry the 1 to the next calculation. This is because there was no place to the right to shift this value. You should
+ 1 also notice that there is now an empty section in the register at the left. When a
1 0 0 1 0 1 0 0 binary number is shifted, the resulting empty sections are, again, filled with a 0.
0 0 0 1 1 1 1 0
0 0 0 1 0 1 1 0
0 1 0
You already know that the first binary number converted to a denary number is
The next calculation is 1 + 0 + 1, which results in 1 + 1. Rule 3 means the
44. If you convert the binary number after the logical right shift has been
result is 10. Write the 0 in the answer section again and carry the 1.
performed, you get the denary number 22. This means that each logical shift to
+ 1 1 the right divides the binary number by 2.
1 0 0 1 0 1 0 0 Consider another binary number:
0 0 0 1 1 1 1 0
0 0 1 0 1 1 1 0 1 1 0 0
The next calculation is 1 + 1 + 1. Rule 4 means the result is 11. Write 1 in the When a logical left shift is performed on the binary value the result is:
answer section and carry 1.
1 1 0 1 1 0 0 0
+ 1 1 1
1 0 0 1 0 1 0 0 When the first binary number is converted to a denary number, the result is
0 0 0 1 1 1 1 0 236. When the binary number is converted after the logical shift to the left has
1 0 0 1 0 been performed, the denary value is 216. You should notice that 236 multiplied
by 2 is not 216. Therefore, one of the problems with a logical shift is that data
The next calculation is 1 + 0 + 0, which results in 1 + 0. Rule 2 means the can lose its integrity as vital bits can be removed from the register.
result is 1. Write 1 in the answer section. There is no carry this time.
More than one logical shift can be performed on a register. For example, two
+ 1 1 1 logical shifts to the left can be performed. This time, each value in the register
1 0 0 1 0 1 0 0 is shifted two places to the left.
0 0 0 1 1 1 1 0
The binary value:
1 1 0 0 1 0
1 1 1 0 1 1 0 0
The next calculation is 0 + 0. Rule 1 means the result is 0. Write 0 in the
answer section. would become:
+ 1 1 1 1 0 1 1 0 0 0 0
1 0 0 1 0 1 0 0
0 0 0 1 1 1 1 0 Questions
0 1 1 0 0 1 0
5 Describe what happens in a logical binary shift.
The final calculation is 1 + 0. Rules 2 means the result is 1. Write 1 in the
answer section. 6 Perform two logical shifts to the right on the binary number 11101100.
+ 1 1 1
1 0 0 1 0 1 0 0
0 0 0 1 1 1 1 0
1 0 1 1 0 0 1 0
Therefore, when the binary numbers 10010100 and 00011110 are added, the
answer is 10110010.
Questions
Negative binary numbers Most images use a lot more colours than black and white. Each colour has its
All the binary numbers that you have used so far have been positive binary own binary values. Colours are created by computer screens using the Red
numbers. Numbers can sometimes be negatives number though, for example, Green Blue (RGB) colour system. This system mixes the colours red, green
−150. How are negative numbers represented as binary? Binary only has two and blue in different amounts to achieve each colour.
values that can be used, a 0 and a 1, so you can’t just put a minus symbol (−)
in front of the number, as that symbol doesn’t exist in binary. Therefore, a ACTIVITY 1.3
method exists that can be used to represent negative binary numbers and it is
called two’s complement. Most modern computers use this method. Use the internet to find an RGB colour scale. You should notice that each
The method of two’s complement is a simple one. First you invert all the values colour in the scale is first presented as hexadecimal. The first two
in the binary number (change the 1s to 0s and the 0s to 1s), then you add 1 to hexadecimal values are the amount of red, the second two the amount of
the result. You can use this process to find out how the denary value −35 is blue and the last two the amount of green.
represented as binary. Practise your hexadecimal to binary conversion by converting your
Convert 35 to a binary number: favourite colour to its binary value.
0 0 1 0 0 0 1 1
Most images are created using thousands of pixels. Each of those pixels
Invert each of the values in the binary number:
needs quite a lot of data. Multiply that by the thousands of pixels that make up
1 1 0 1 1 1 0 0 the image and that is a huge amount of data. This is why image files can often
be so large in size.
Then simply add 1:
Each image has a resolution and a colour depth. The resolution is the number
1 1 0 1 1 1 0 1 of pixels wide and the number of pixels high that are used to create the image.
The colour depth is the number of bits that are used to represent each colour.
11011101 is the binary representation of −35 using the two’s complement For example, each colour could be represented using 8-bit, 16-bit or 32-bit
method. binary numbers (see Figure 1.3). The greater the number of bits, the greater
the range of colours that can be represented.
1.3 How do computers represent text, images and If the colour depth of an image is reduced, the quality of the image is often
reduced.
sound?
You have already learnt that computers only process binary. This means that
all data must be converted to binary to be processed by a computer. You have
already looked at converting numbers, but text, images and sound all have to
be converted to binary too, so they can be processed by a computer. How is
this done?
Figure 1.2: An image created just from black and white pixels
You will notice that the two sound waves look different. This is because the When you know this information, you can perform a simple calculation to get
number of samples taken is too far apart, so vital data in between time the size of the sound file, which is:
samples has been lost. This will result in a lack of accuracy in the sound that is sample rate × sample resolution × length of soundtrack
recorded. Therefore, more samples need to be taken each second to improve
the accuracy of the recorded sound. The number of samples taken in a second Therefore, if you have the following information about a sound file:
is called the sample rate. Sample rates are measured in hertz. 1 hertz is equal • length of 30 seconds
to 1 sample per second. A common sample rate is 44.1 khz (kilohertz), this
• sample rate of 44,100 hz
would require 44 100 samples to be taken each second. That is a lot of data! If
the sample rate is increased, the amount of data required for the recording is • sample resolution of 8 bits,
increased. This increases the size of the file that stores the sound. you can calculate the size of the sound file as follows:
Further data is required to represent sound, and this is the sample resolution. • 44 100 × 8 = 352 800 (this means there are 352 800 bits per second)
This is the number of bits that are used to represent each sample. A common
sample resolution is 16-bit. The higher the sample resolution, the greater the • 352 800 × 30 = 10 584 000 (this means there are 10 584 000 bits in
variations in amplitude that can be stored for each sample. This means that the sound file).
aspects such as the loudness of the sound can be recorded more accurately. You will be asked to calculate the size of a sound file to a certain unit of
This will also increase the amount of data that needs to be stored for each measurement. The answer given (10 584 000) is the number of bits that are
sample. This increases the size of the file that stores the sound. in the sound file. If you wanted to know how many bytes are in the sound
file, you need to divide the final answer again by 8, as there are 8 bits in
1.4 Measuring data storage each byte, for example:
Earlier in the chapter, you learnt that all data need to be converted to digital 10 584 000 ÷ 8 = 1 323 000 bytes
data to be processed by a computer, and you now know how that is done for If you wanted to know how many mebibytes the file was, you need to divide
different types of data. But how is data measured when it is stored? the answer in bytes by 1024, then by 1024 again, for example:
1 323 000 ÷ 1024 ÷ 1024 = 1.3 MiB (to 1 decimal place)
COMPUTER SCIENCE IN CONTEXT
There are times when you will need to know the size of a data file, such 1.5 Data compression
as when you are attaching a file to an email. Most email providers have a
file size limit, so you need to know the size of that file, to know if it can be You may already have experience of having large files and struggling to have
attached to your email. enough storage space to store them. One thing that can be done to reduce the
size of a file is compression.
Compressing a file will reduce the size of the file that can have several
Data is measured using different units, which are shown in Table 1.2. benefits, such as:
Unit Description • Not as much storage space is needed to store the file.
Bit This is the smallest measurement for data • It will take less time to transmit the file from one device to another.
Nibble There are 4 bits in a nibble • It will be quicker to upload and download the file.
Byte There are 8 bits in a byte • Not as much bandwidth is needed to transmit the file over the internet.
Kibibyte (KiB) There are 1024 bytes in a Kibibyte There two type of compression that can be used, lossy and lossless. Each
compresses the data in a different way.
Mebibyte (MiB) There are 1024 Kibibytes in a Mebibyte
Lossy compression uses a compression algorithm that finds the unnecessary
Gibibyte (GiB) There are 1024 Mebibytes in a Gibibyte and redundant data in the file. This data is permanently removed from the file.
Tebibyte (TiB) There are 1024 Gibibyte in a Tebibyte This type of compression is mainly used on an image file or a sound file.
Pebibyte (PiB) There are 1024 Tebibytes in a Pebibyte Unnecessary data in an image file that could be removed are colours that the
human eye cannot distinguish. This means that a lossy compression algorithm
Exbibyte (EiB) There are 1024 Pebibytes in an Exbibyte
for an image file could reduce the size of the file by reducing the colour depth.
Table 1.2: Data measuring units It could also reduce the size of the file by reducing the image resolution,
reducing the number of pixels used to create the image.
Although most computers will calculate the size of a file for you, you need to be Unnecessary data in a sound file that could be removed are sounds that
able to show that you can do this manually for the exam. This is just for an cannot be heard by the human ear. It could also be the removal of softer
image file and a sound file. sounds that are played at the same time as louder sounds, as humans will only
hear the louder sound. The method that is used to find these kinds of sounds
SKILLS FOCUS 1.3 in a sound file is called perceptual music shaping. This is the most common
type of method that is used in the file format MP3. The size of a sound file can
CALCULATING THE SIZE OF A FILE also be reduced by reducing the sample rate and the sample resolution.
There are several pieces of information that you need to know to calculate
the size of an image file, these are: Questions
• the number of images in the file 7 Why do you think lossy compression is not commonly used on text files?
• the resolution of the image 8 Will lossy compression affect the quality of an image? Why?
• the colour depth of the image. 9 Will lossy compression affect the quality of a sound recording? Why?
When you know this information, you can perform a simple calculation to get SELF ASSESSMENT
the size of the image file, which is:
What were the points that you thought about regarding lossy compression
width of image × height of image × colour depth of image × number of to answer question 7? Did you relate these points back to why lossy
images in file compression is not suitable for a text file, or did you just make points
Therefore, if you have the following information about an image file: about the drawbacks of lossy compression in general?
• 10 images in the file
• image resolution is 100 × 150 Lossless compression uses a compression algorithm to reduce the size of the
file, without permanently removing any data. A common method that can be
• colour depth is 8-bit colour,
used to do this is by finding repeating data in the file and grouping this data
you can calculate the size of the image file as follows: together. For example, consider the following message:
• 100 × 150 = 15,000 (this means there are 15 000 pixels in the image) WHEN IT IS SNOWING HEAVILY LOOK OUTSIDE.
• 15 000 × 8 = 120,000 (this means that there are 120 000 bits in each LOOK OUTSIDE IT IS SNOWING HEAVILY.
image)
Excluding the spaces between the words and the full stops, the message has a
• 120 000 × 10 = 1 200 000 (this means there are 1 200 000 bits in the total of 62 characters. 1 character requires 1 byte of storage, so 62 bytes of
image file). storage would be needed to store this message.
You will be asked to calculate the size of an image file to a certain unit of When you look at the message, you should notice that it consists of words that
measurement. The answer given here (1 200 000) is the number of bits that are mostly repeated. Instead of storing all 62 characters individually, the words
are in the image file. If you wanted to know how many bytes are in the image and the positions at which they occur in the message can be stored in a lookup
file, you need to divide the final answer by 8, as there are 8 bits in each byte, table, for example:
for example:
Word Position(s) in the message
1 200 000 ÷ 8 = 150 000 bytes
WHEN 1
If you wanted to know how many kibibytes the file was, you need to divide
the answer in bytes by 1024, for example: IT 2, 10
Questions SNOWING 4, 12
1 How many times would you need to divide the answer in bytes by 1024 HEAVILY 5, 13
to find the answer in Gibibytes? LOOK 6, 8
2 How many pixels would there be in an image that has a resolution of OUTSIDE 7, 9
1000 × 1500?
The lookup table needs 1 byte for each character in each word and 1 byte for
There are several pieces of information that you need to know to calculate each position the word occurs in the message. Therefore, 33 bytes are needed
the size of a sound file, these are: to store the words and 13 bytes to store the positions, giving a total of 46
• the length of the soundtrack bytes. This is much less than the 62 bytes we required with our original
method. No data has been lost and we have reduced our storage requirements
• the sample rate of the soundtrack
by 26%, quite a saving! To recreate the message, the computer simply
• the sample resolution of the soundtrack. retrieves the words and places them in the positions allocated.
A similar process can be applied to an image file with a lossless compression
algorithm called run length encoding (RLE). This algorithm will group
together repeating pixels and store how many times they occur. For example,
consider the simple image in Figure 1.6:
EXAM-STYLE QUESTIONS
1 There are two different types of data, known as analogue data and
digital data.
If W is white, Y is yellow, R is red and G is green, RLE could compress the • 90D
image into the following data:
b Write the seat number that would be displayed for the
12W, 3Y, 5W, 2Y, 1R, 2Y, 3W, 2Y, 3R, 2Y, 3W, 2Y, 1R, 2Y, 5W, 3Y, 7W, 1G, 5W, binary number 000010011100. [2]
2G, 1W, 1G, 1W, 2G, 4W, 3G, 7W, 1G, 4W. [Total: 6]
This means that the amount of data can be reduced as pixels are grouped 4 Two registers store the given 8-bit binary values. Register 1 stores
together and the data for each pixel does not need to be stored. The resolution 00110111 and register 2 stores 01110011.
of the image is stored with the data, so that the computer knows the size to
recreate it when the data is decompressed. a Add the two binary values and write the result of the
calculation. Show all your working. [3]
ACTIVITY 1.4 b A logical left shift of three places is performed on Register
1. Write the contents of register 1 after the logical shift
Why don’t you try creating a simple image and writing out the RLE data has been performed. [1]
for it? You could then give it to your friend, along with the image [Total: 4]
resolution, and they can have fun trying to recreate your image.
5 Show how the value −28 is represented in binary using two’s
Peer Assessment complement. Show all your working. [2]
Ask your friend whether you got the RLE correct for your image in Activity 6 A student wants to store some images that they have taken with
1.4. Ask them if you could have done anything to make your RLE any digital camera. They do not have enough storage space on their
clearer. Ask them if you missed any important data. external hard disk drive to store the images at their current file size.
After studying this chapter, think about how confident you are with the
different topics. This will help you to see any gaps in your knowledge and
help you to learn more effectively.
You might find it helpful to rate how confident you are for each of these
statements when you are revising. Youshould revisit any topics that you
rated ‘Needs more work’or ‘Getting there’.
I can... See Needs Getting Confident
topic more there to move
work on
explain why data needs to be 1.1
converted to binary to be
processed by a computer.
convert between denary numbers 1.1
and binary numbers.
convert between denary numbers 1.1
and hexadecimal.
convert between binary numbers 1.1
and hexadecimal.
provide examples of the use of 1.1
hexadecimal in computer science.
explain why hexadecimal is used 1.1
in computer science.
add two 8-bit binary numbers. 1.2
explain what is meant by an 1.2
overflow error.
perform a logical binary shift on a 1.2
binary number, including left and
right shifts and multiple shifts.
use two’s complement to represent 1.2
negative numbers.
explain how character sets are 1.3
used by a computer to represent
text.
explain how pixels are used by a 1.3
computer to create images.
explain how the file size of an 1.3
image is affected by the image
resolution and colour depth.
explain how a sound wave is 1.3
sampled by a computer.
explain how the file size of a sound 1.3
recording is affected by the sample
rate and sample resolution.
understand how the size of a data 1.4
file is measured.
calculate the size of an image file. 1.4
calculate the size of a sound file. 1.4
understand the need for data 1.5
compression and the effect it has
on a file.
explain how different types of data 1.5
are compressed using lossy
compression.
explain how different types of file 1.5
are compressed using lossless
compression.