AQA GCSE CompSci Textbook 8525
AQA GCSE CompSci Textbook 8525
eTextbook.
Whiteboard eTextbooks are online interactive versions of the printed textbook that enable teachers to:
●● Display interactive pages to their class
Student eTextbooks are downloadable versions of the printed textbooks that teachers can assign to
students. Students can:
●● Download and view them on any device or browser
Find out more and sign up for a free trial – visit: www.hoddereducation.co.uk/dynamiclearning
FOR THE
8525
SPECIFICATION
AQA
GCSE
(9–1)
Computer
Science Second Edition
George Rouse
Lorne Pearcey
Gavin Craddock
1 FUNDAMENTALS OF ALGORITHMS 1
1.1 Representing algorithms 1
1.2 Efficiency of simple algorithms 8
1.3 Sorting and searching algorithms 9
2 PROGRAMMING 25
2.1 Data types 26
2.2 Programming concepts 28
2.3 Arithmetic operations 37
2.4 Relational operations 38
2.5 Boolean operations 40
2.6 Data structures 42
2.7 Input and output 46
2.8 String-handling operations 46
2.9 Random number generation 49
2.10 Structured programming and subroutines 50
2.11 Robust and secure programming 55
GLOSSARY 221
INDEX 252
ACKNOWLEDGEMENTS 257
iv
Important words
Highlighted in green, these are terms that you will be expected to know and understand in
your exams.
Important words
You will need to know and understand the following terms:
algorithm
decomposition
abstraction
Tech terms
Jargon or technical definitions in blue that you may find useful.
Tech terms
Inverter An alternative name for a NOT gate, because the output inverts the input.
Key point
An important idea or concept.
Key point
A computer program is an implementation of an algorithm – an algorithm is not a computer program!
Worked examples
Used to illustrate an idea or a concept, these will guide you through the reasoning behind
each step of a calculation or process.
Worked example
FOR a ← 1 to 4
FOR b ← 1 to 3
OUTPUT a * b
ENDFOR
ENDFOR
Knowledge check
Quick check-ins that help you to recap and consolidate your understanding of the
previous section.
Knowledge check
1 Define the following terms:
(a) Decomposition
(b) Abstraction
2 A programmer is creating software to send and receive encrypted messages
via email. Describe how decomposition can be used to allow this problem to
be solved.
Question practice
More formal questions to help you to prepare for both examination papers.
Answers
Answers to all of the Knowledge check and Question practice questions
are at the back of the book and also at www.hoddereducation.co.uk/
AQAGCSEComputerScience.
vi
FUNDAMENTALS
OF ALGORITHMS
Knowledge check
1 Define the following terms:
(a) Decomposition
(b) Abstraction
2 A programmer is creating software to send and receive encrypted messages via email.
Describe how decomposition can be used to allow this problem to be solved.
3 A chess club develops a system to store details about games played. For each game,
the winner's and loser’s names are stored alongside the date that the game was played.
Explain how abstraction has been used in the development of this system.
Input refers to data that is given to the algorithm by the user. This may be typed in via the
keyboard, entered with another input device such as a microphone or read in from an external
data file.
Output is the data that is given back to the user by the algorithm. This may be done with
a message on the screen, using another output device such as a printer or by writing to an
external data file.
Processing describes the steps that the algorithm takes in order to solve the problem. This
stage involves processing the given input in order to produce the desired output.
Going back to the example of the system to sell T-shirts, what are the inputs, outputs and
processes for the section of the system that allows the user to search for suitable T-shirts?
The inputs include everything that the system requires the user to enter: for example, the size,
colour and style of T-shirt that they require. Another input would be an external file containing
details of all the T-shirts available.
With these inputs, the system will then carry out processes to find T-shirts to match the user’s
search criteria, such as only selecting those in the correct size and colour and excluding any
that are out of stock.
Once this has been completed, a list of matching T-shirts will be produced as an output to the user.
Flowcharts
The inputs, processes and outputs can be put together into an algorithm by using a flowchart.
This is a graphical representation of an algorithm and uses symbols to denote each step, with
arrows showing how to move between each step.
A flowchart may use any of the following symbols:
All flowcharts begin and end with the terminal shape, indicating the start and end of the
flowchart.
Inputs and outputs are represented by a parallelogram, with decisions using a diamond shape.
Decision boxes must have two possible outputs: True/False or Yes/No.
All other processes are shown as a rectangle.
Where algorithms are decomposed into separate subroutines, a rectangle with two additional
vertical lines is used to show a call to a different subroutine.
The following flowchart shows part of an algorithm for the T-shirt system that deals with
re-ordering T-shirts when stock runs low.
Start
Enter ItemCode
Read StockLevel,
ReorderLevel
from User
Is StockLevel
True
≤ Call Reorder
ReorderLevel? Subroutine
False
End
Pseudo-code
Alternatively, an algorithm may be represented using pseudo-code. Pseudo-code is a
textual, English-like method of describing an algorithm. It is much less strict than high-level
Key point programming languages, although it may look a little like a program that could be entered
directly into a computer. The same T-shirt reordering system that was described in a flowchart
In general, pseudo-code could also be represented in pseudo-code as follows:
is not strictly defined so
many variations would be ItemCode ← USERINPUT
acceptable. For example,
the keyword OUTPUT StockLevel ← USERINPUT
could instead be replaced
with PRINT, or even ReorderLevel ← USERINPUT
DISPLAY – as long as the
steps to be taken are clear, IF StockLevel ≤ ReorderLevel THEN
that is sufficient.
ReOrder()
Program code
Program code refers to instructions given in a high-level language. For the AQA GCSE
Computer Science specification, you must choose to use either Python, VB.Net or C#; each of
these languages has a separate examination paper.
Where answers are requested as program code, it is important that you are as precise with the
syntax as when you are actually coding. Your code answers should work if they were typed
into your computer.
The following shows the T-shirt ordering algorithm written in each of these high-level languages:
Python
ItemCode = input("enter item code")
StockLevel = int(input("enter stock level"))
ReorderLevel = int(input("enter reorder level"))
if StockLevel <= ReorderLevel:
ReOrder()
print("stock ordered")
else:
print("stock not ordered")
VB.Net
Dim ItemCode As String
Dim StockLevel As Integer
Dim ReorderLevel As Integer
ItemCode = Console.Readline()
StockLevel = Console.Readline()
ReorderLevel = Console.Readline()
If StockLevel <= ReorderLevel Then
ReOrder()
Console.WriteLine("stock ordered")
Else
Console.WriteLine("stock not ordered")
End If
C#
string ItemCode;
int StockLevel;
int ReorderLevel;
ItemCode = Console.Readline();
StockLevel = Convert.ToInt32(Console.Readline());
ReorderLevel = Convert.ToInt32(Console.Readline());
if (StockLevel <= ReorderLevel)
{
ReOrder();
Console.WriteLine("stock ordered");
}
else
{
Console.WriteLine("stock not ordered");
}
By tracing this algorithm using a trace table, we can see that it makes the choice of whether to
reorder the stock based on whether the current stock level falls below the reorder level.
We could also have traced through with stock values that were just equal to the reorder
level, and with another item that was out of stock, to be sure that this algorithm works
perfectly in every scenario. (We will consider this more thoroughly when discussing testing
in Chapter 2.)
Key point
A trace table shows the values of each variable after each step has been executed. Although the
item code is only entered on line 1, it still holds the same value throughout the rest of the program
and so its value is repeated in later lines of the trace table.
Knowledge check
4 The following algorithm has been designed to decide which of two numbers is the largest. Complete the trace table to
check that the algorithm works correctly when the values 8 and 5 are entered by the user.
01 NumOne ← USERINPUT
02 NumTwo ← USERINPUT
03 IF NumOne ≥ NumTwo THEN
04 OUTPUT NumTwo
05 ELSE
06 OUTPUT NumOne
07 ENDIF
#Version 2
FOR x ← 1 to 5
OUTPUT x
ENDFOR
#Version 3
x ← 1
WHILE x ≤ 5
OUTPUT x
x ← x + 1
ENDWHILE
Each of the algorithms above will produce exactly the same output. If we changed the
algorithm to print out the numbers 1 to 100 000, it is perhaps obvious that the first example
would be more time-consuming to write out whereas the others would be simpler to change.
However, this does not in itself make the first algorithm any less efficient than the other two.
The efficiency of an algorithm is the time taken for a computer to complete that algorithm.
Because computers all run at different speeds, we count up the number of steps in an algorithm
as a rough guide to its efficiency.
The following two algorithms complete the same task, of finding the greatest common divisor
of two numbers
#Algorithm 1
a ← USERINPUT
b ← USERINPUT
WHILE b ≠ 0
IF a > b THEN
a ← a - b
ELSE
b ← b - a
ENDWHILE
OUTPUT a
#Algorithm 2
a ← USERINPUT
b ← USERINPUT
gcd ← 0
IF a > b THEN
large ← a
ELSE
large ← b
ENDIF
FOR x ← 1 TO large
IF (a MOD x = 0) AND (b MOD x = 0) THEN
gcd ← x
ENDIF
ENDFOR
OUTPUT gcd
Algorithm 1 does this using a special mathematical technique (called the Euclidian algorithm) that
works by subtracting one number from the other, depending on which is larger, until zero is reached.
Algorithm 2 simply divides both numbers by every possible integer. Both will produce the
same result but algorithm 2 will take many more steps to find the answer. We can therefore say
that algorithm 1 is more efficient.
Beyond the
The efficiencies of these two algorithms also depend on the input values. Running the
spec
algorithm with numbers such as 10 and 50 will show a small difference in efficiency between
Computer Scientists them, but if numbers in the millions were used algorithm 1 would be much more efficient
use ‘Big O notation’ to than algorithm 2.
measure mathematically
how efficient algorithms 1.3 Sorting and searching algorithms
are. Big O attempts to
measure the change in One of the great things about an algorithm is that it can be reused. Once a computer scientist
efficiency as the size of has written down a clever set of instructions for how to do something, other people can
the data input increases. simply follow those instructions to solve the same problem.
This is covered fully in A sorting algorithm is a set of instructions used to put a list of values into order. A
the A-level Computer searching algorithm is used to find a value within a list, or to confirm that value is not
Science specification. present in the list.
Key point
The list now appears to be in numerical order. However, the algorithm only stops when
a pass is completed without any swaps taking place. This is not yet the case.
The final pass of the algorithm compares each pair of numbers and finds no numbers that
need to be swapped. The algorithm is therefore complete and the values are in order.
The bubble sort algorithm gets its name because numbers ‘bubble’ to the top after every pass.
10
We can write out the bubble sort algorithm in very informal pseudo-code as follows:
REPEAT
ENDIF
Key point
At GCSE level, you will not be expected to remember the sorting and searching algorithms in
pseudo-code, but you are expected to understand how they work.
Merge sort
The merge sort algorithm uses a ‘divide and conquer’ approach to split data up into
Key point individual lists and then merge them back together in order. The way that the lists are merged
You will be expected to back together is key to understanding how this algorithm works. For example, we have a list like
know how to perform a this one below and we want to sort it in ascending order (from lowest to highest):
merge sort on a list with 7 2 9 4 3 8 5 1
an even or odd number
of elements. With an odd First, in the ‘divide’ stage the list of values is split into two separate sublists. Each sublist is
number of elements there repeatedly split in half until we have individual lists of size 1 each.
are two choices of where to
7 2 9 4 3 8 5 1
divide lists – you can choose
either but you must apply Then each pair of lists are merged together into new lists in the ‘conquer’ stage. Where there is an
your choice consistently. uneven number of lists, the odd list will simply remain unmerged until the next step in the process.
Each of the merge stages
must resemble the divide
When two lists are merged together, the first two numbers in each of the lists are compared
stages, just with elements in and whichever should be first is taken to be first in the new list. This process is repeated until
a different order. all numbers have been inserted into the new list.
7 2 9 4 3 8 5 1
2 7 4 9 3 8 1 5
Here, 7 and 2 are compared, with 2 being inserted into a new list before 7. Similarly, 4 is inserted
before 9 in the next merged list. This continues for the other pairs of lists, merging them
together into four new lists.
The merging process is repeated again to merge pairs of lists together. This time the first list
is made of 2 and 7, and the second list is made of 4 and 9. The algorithm compares the first
numbers in each list, 2 and 4, to decide which value will be first in the new list. 2 is inserted
into the new list. Next, 7 and 4 are then compared, with 4 being inserted. Then, 7 and 9 are
compared, with 7 being inserted before 9 into the first new list.
The same process is then repeated for the lists made of 3 and 8, and 1 and 5, leaving two new
lists in order, each made of four numbers. 11
2 7 4 9 3 8 1 5
2 4 7 9 1 3 5 8
The merging process is again repeated with the final two lists. The first numbers in each list (2
and 1) are compared to decide which value will be first in the merged list, with 1 being inserted.
2 is then compared against 3, with 2 being inserted into the new list next. This continues until
all numbers have been merged from the two lists into the final list. This final list is now in order.
2 4 7 9 1 3 5 8
1 2 3 4 5 7 8 9
Key point
At any point in the merging stage of this algorithm, each merged list is always in order. This means
that it is only the first numbers from each list that need to be considered when deciding on how to
merge them.
We can write out the merge sort algorithm in very informal pseudo-code as follows:
REPEAT
When all numbers are split up into separate lists, the merge stage can begin. This uses the
following steps in very informal pseudo-code:
REPEAT
REPEAT
REPEAT
If at any stage an odd number of lists are present, the odd list can simply be ignored until the
next iteration.
Knowledge check
5 Explain how a bubble sort would sort the values [6, 9, 2, 5, 8] into order.
6 A merge sort is an example of a divide and conquer algorithm. State what happens
during the divide stage.
Searching algorithms
A searching algorithm is used to find an item of data in a list, or to confirm that it is not in the
list. The simplest searching algorithm is a linear search.
Linear search
A linear search is carried out by inspecting each item of the list in turn to check if it is the
desired value. If it is, we have found the item; if it is not, the next item in the list must be
checked.
If the algorithm gets to the end of the list without finding the item, then it is not in the list.
7 2 9 4 3
To find the value 9 in this list, the algorithm would first check 7 and then check 2 before finally
finding 9. To find the value 8, the algorithm would check every item in the list (7, 2, 9, 4 and 3).
Only after checking the last value can we can be sure that 8 is not in the list.
A linear search is simple but inefficient. If we have a list of a million values, the algorithm would
have to check all one million of them before being sure that that a particular value was not in
the list.
We can write out the linear search algorithm in very informal pseudo-code as follows:
REPEAT
Output value
ELSE
ENDIF
Binary search
A much more efficient algorithm to find values in a list is a binary search. However, this
algorithm has the pre-requisite that the list it searches must be in order. A binary search on an
unsorted list will not work.
The binary search algorithm picks the middle value in the sorted list. ‘Middle’ means there are
equal numbers of values either side of it. If there are an even number of values in the list then
there isn’t an exact middle value – however, generally the value to the left of the middle is
chosen. (Either side can be picked as long as we are consistent.)
13
If the middle value is the one that we are searching for then the algorithm finishes. However, if
not, then the algorithm can discard half of the list because the value we are looking for cannot
be in it. It can discard the lower half of the list if the middle value is smaller than the one we
are searching for (as all of the values in the lower half will be smaller than the middle value);
or it can discard the upper half of the list if the middle number is larger than the one we are
searching for (as all of the values in the upper half will be larger than the middle value). Either
way, we always also discard the middle value.
If we get to a situation where the list only has one item and it is not the one that we are
searching for, then the value is not in the list.
Worked example
The list below is in alphabetical order and so can be used in a binary search. We will look for
the value Q in this list.
A C D F H K P Q S T V W Z
We first take the middle value P. This is not the value that we are looking for and is smaller
than Q alphabetically, so we can discard the lower half of the list, up to and including P.
Q S T V W Z
We now have a list of six values. As there is no middle value, we pick the value to the left of
the middle, which is T. This is the not the value that we are looking and T is larger than Q
alphabetically, so the upper half of the list (including T) can be discarded.
Q S
We now have a list of two values. Again, there is no middle value so we pick the value to
the left of the middle which is Q. This is the value that we are searching for and so the
algorithm stops.
We can write out the binary search algorithm in very informal pseudo-code as follows:
REPEAT
Output value
ENDIF
14
Knowledge check
7 Explain how a linear search would find the value 18 in the list [1, 8, 6, 2, 18, 14, 7].
8 Which value would be the first to be compared in a binary search through the list
[A, B, C, D, E]?
9 How does a linear search determine that a value does not appear in a list?
15
16
As an example, the algorithm in the figure below will decide whether a positive number entered
is odd or even using repeated subtraction.
Start
Enter Number
TRUE
Is Number = 0? Output ‘Even’
FALSE
TRUE
Is Number = 1? Output ‘Odd’
FALSE
Number = Number − 2
End
17
Pseudo-code
■ Pseudo-code is a textual representation of an algorithm.
■ Pseudo-code enables programmers to communicate algorithms to other programmers,
showing the steps used without worrying about which language they are using.
The pseudo-code algorithm below carries out the same algorithm as the flowchart shown
previously – finding whether a positive number is odd or even through repeated subtraction.
Number ← USERINPUT
WHILE Number ≥ 0
IF Number = 1 THEN
OUTPUT 'odd'
ELSE IF Number = 0
OUTPUT 'even'
END IF
Number ← Number – 2
ENDWHILE
Program code
Program code is code that is written in a high-level language. As you are studying AQA’s GCSE
Computer Science specification, this will be either Python, VB.net or C#.
Program code in answers must be precise.
each point, the value of each variable and any outputs are recorded.
A table such as the one shown below is used. More columns are added if more variables are used.
If the program repeats certain lines, this is reflected in the trace table. Each row shows one
line that is executed and lines of code can be repeated as many times as required.
The completed trace table below shows the previous algorithm running to check whether 5
is an odd or even number.
18
19
REPEAT
REPEAT for each pair of numbers in the list
# where list[x] is 1st item in a pair
# and where list[x + 1] is 2nd item in a pair
IF list[x] > list[x + 1] THEN
swap list[x], list[x + 1]
ENDIF
UNTIL all pairs of values checked
UNTIL no swaps made
When all numbers are split up into separate lists, the merge stage can begin. This uses the
following steps in very informal pseudo-code:
REPEAT
REPEAT
REPEAT
Compare the first value in both lists
Insert larger of two values into new merged list
Remove value from old list
UNTIL all numbers in pairs of lists are merged
UNTIL each pair of lists have been considered
UNTIL all lists are merged
If at any stage an odd number of lists are present, then one list can simply be ignored until the
next iteration.
● The merge sort is much more efficient than the bubble sort.
● It will sort a large list of random values into order in a quicker time than a bubble sort.
20
Searching algorithms
Linear search
A linear search uses the following steps:
REPEAT
Check one value (from the start)
IF value matches what is being searched for THEN
Output value
ELSE
Move to next value
ENDIF
UNTIL number is found OR end of list is reached
The linear search is relatively inefficient, but it works on any list, regardless of whether it is in
any particular order.
Every single value in the list needs to be checked before you can be certain that a value is not
present in a list.
Binary search
A binary search requires the list of values to be in order. It uses the following steps:
REPEAT
Pick the middle value in a list (if even number of values, pick left-
of-middle value)
IF value matches what is being searched for THEN
Output value
ELSE IF value searched for > middle value THEN
Discard middle value AND lower half of list
ELSE IF value searched for < middle value THEN
Discard middle value AND upper half of list
ENDIF
UNTIL (value found) or (list is of size 1 and value is not found)
■ A binary search is highly efficient. If an ordered list of one million numbers is used, the
binary search could find a number in the list with no more than 21 comparisons. The linear
search by contrast could take up to one million comparisons.
■ However, the binary search will only work if the list of values is ordered. Therefore, it cannot
always be used.
21
03 An amateur football team wants a computer program to calculate the points scored. The
user inputs:
• the number of games won
• the number of games drawn.
There are 3 points for a win, 1 for a draw and 0 for a loss.
The program should prompt the user for the inputs and output a suitable message with
the points total.
Using AQA pseudo-code or a high-level language that you have learned, write a program
to input the data above and output the total points scored. [6 marks]
22
04 Here is an algorithm that is intended to collect and store the names of people going into
an event. Only 15 people are allowed to enter the event.
number
name[1] ← USERINPUT
number ← number + 1
ENDWHILE
OUTPUT number
04.3 Add to the algorithm so that it outputs all the names entered. [4 marks]
y ← 0
WHILE y < 6
y ← y + 1
x ← x + y
ENDWHILE
OUTPUT x
x y output
06 Show the stages of a bubble sort when applied to the following data:
Elephant, Dog, Cat, Dolphin, Sheep, Frog [4 marks]
23
08.2 Outline the advantage of a merge sort over a bubble sort. [2 marks]
09.2 Explain why a binary search could not be used with this list to find Harry. [1 mark]
10.2 State the number of comparisons needed to find MA267 using a binary
search. [1 mark]
10.3 State the number of comparisons needed to find MA267 using a linear
search. [1 mark]
24
PROGRAMMING
25
2.9 Random number generation in a programming language ➤ Understand and use local variables
➤ Be able to use random number generation within a ➤ Describe and explain the advantage of a structured
computer program approach to programming
2.10 Structured programming and subroutines (procedures 2.11 Robust and secure programming
and functions) ➤ Understand simple data validation and authentication
➤ Understand the concept and advantages of subroutines routines
➤ Describe how parameters are used to pass data within ➤ Test algorithms and programs, correcting errors
programs ➤ Understand and justify the choice of test data, including
➤ Use subroutines that return values to the calling normal, boundary and erroneous data
routine
Key point
Paper 1 requires significant knowledge and understanding of programming. It is a requirement of the
AQA GCSE Computer Science course that you are able to program in one of the specified high-level
languages (Python, VB.Net or C#). Assessment of programming skills will only be made through this
written examination.
➤ Understand syntax and logic errors
Some questions in the examination will be presented in AQA Pseudo-code. Full details of this are
Identify
➤given on theand
AQAcategorise errorsquestions
website. Other within algorithms and programs
will be presented in Python, VB.Net or C#, depending
upon the option chosen by your teacher; AQA provide a separate examination paper for each of
these languages.
Examples in the main text are given in AQA Pseudo-code. Where possible, all worked examples
given in this chapter are written in AQA Pseudo-code, Python, VB.Net and C#. Please ensure that
you are aware which of these you are studying.
Please refer to www.aqa.org.uk for full details of the assessment.
Integer
Integers are whole numbers, positive or negative, that have no decimal or fractional part.
Integers are used for counting or storing quantities. For example:
score ← 25
highScore ← 100
numOfAttempts ← 0
26
Character
A character is a single item from the character set used on the computer, such as H, r, 7 or
&. Uppercase and lowercase are different characters and space is also a character.
When assigning a character to a variable, quotation marks are required to indicate that the
value to be assigned is a character. For example:
a ← 't'
b ← '4'
c ← '%'
d ← ''
String
A string data type stores a collection of characters and is typically used for names, addresses
or other textual information. Note that numbers and symbols can also be characters and so
can be included in a string.
Just like characters, when assigning a string to a variable, quotation marks are required:
a ← 'the colour blue'
b ← '47 times'
c ← '95% increase'
d ← 'p@55w0rd'
27
Key point
Strings and characters require quotation marks around the values to be assigned. This is to
differentiate them from variables. Compare the following lines of code:
colour ← 'blue'
colour ← blue
The first line assigns the string value of 'blue' to the variable colour. However, the second
line treats both colour and blue as variables and assigns the contents of variable blue to the
variable colour. If the variable blue does not exist, this would cause an error in the program.
Knowledge check
1 State whether the following data are real numbers, integers, characters, Boolean or
strings:
(a) 35
(b) &
(c) 3 ≠ 2
(d) twenty
(e) 35.0
(f) 6.63
Key point
A common mistake is to describe a constant as a variable that doesn’t change – variables and
constants are similar, but they are not the same. Would you describe a car as a bike with four
wheels?
Assignment means to give a value to a variable or constant. This is done using the ‘←’ sign
in AQA Pseudo-code and the ‘=’ symbol in Python, VB.Net and C#. The variable or constant
identifier always goes on the left and the value to be assigned goes on the right.
A variable can be assigned a value multiple times, but when a new value is assigned the old
value is overwritten and lost. A constant can only be assigned a value once, usually at the start
of a program.
In most high-level languages, variables and constants are declared (defined) at the beginning
of the program. (Note, however, that Python does not use declarations.)
Worked example
The following program shows a variable and a constant being assigned values, using the
AQA Pseudo-code. Note how the contents of the variable score is changed, but the
constant maxScore is fixed and cannot change.
constant maxScore ← 100
score ← 20
score ← 30
score ← score + 10
After this algorithm is run, maxScore has the value 100 and score has the value 40.
score = 20
playerName = "Kirstie"
VB.Net allows the programmer to declare the variable before it is used with the Dim keyword.
The data type is declared at this point. However, this declaration is optional.
C# makes it compulsory to declare a variable before it is used with the int , float , bool,
char or string keywords.
Once a variable has been declared, its value can be changed by simply reassigning a new value.
It does not need to be declared again.
score = 30 #Python
score = 30 'VB.Net
score = 30; //C#
29
Sequence
Sequence is the execution of statements one after the other, in order. The program runs
from top to bottom and each instruction completes fully before the next one is executed.
Program A Program B
x ← 10 x ← 10
x ← x * 3 x ← x + 1
x ← x + 1 OUTPUT x
OUTPUT x x ← x * 3
Both programs have the same instructions but in a different order. Program A will print out 31
but program B will print out 11. However, in program B the final value of x equals 33 because
there is another line of code after the OUTPUT x statement. The sequence of instructions is
important and changing this can change how the program works.
Selection
Selection is the construct used to make decisions in a program. These decisions are based
on Boolean conditions and the program then takes one of two paths based on this condition.
Key point
A Boolean condition is a statement that can be evaluated to be either True or False. ‘What do I want
for lunch today?’ is not a Boolean condition as the answer could be one of many things, but ‘Do I
want pizza for lunch?’ would be a Boolean condition as the answer could only be True (Yes, I want
pizza) or False (No, I do not want pizza).
False
Condition
True
The most common way of implementing selection is by using IF statements. The IF keyword
is used to define the condition to be evaluated, with the code to be executed if true indented
between the IF and ENDIF keywords.
Worked example
name ← USERINPUT
IF name = 'George' THEN
OUTPUT 'Hello George'
ENDIF
In this example, the condition that is evaluated is whether the inputted name matches the
value given (George). If it does, the third line is executed. If not, the program skips over this
line entirely.
To extend this program to do something else if the condition is false, the ELSE keyword can
be used.
Worked example
name ← USERINPUT
IF name = 'George' THEN
OUTPUT 'Hello George'
ELSE
OUTPUT 'Hello stranger'
ENDIF
But what if we want to check for multiple conditions, each with their own associated code to
run if true? The ELSE IF keyword allows us to do this.
Worked example
name ← USERINPUT
IF name = 'George' THEN
OUTPUT 'Hello George'
ELSE IF name = 'Lorne' THEN
OUTPUT 'Great work Lorne'
ELSE IF name = 'Kirstie' THEN
OUTPUT 'Nice to see you again'
ELSE
OUTPUT 'Hello stranger'
ENDIF
In this example, each possible condition is evaluated in turn. First, the inputted name is
checked against ‘George’. If this is true, the message on line 3 is printed. If not, the second
possible condition (‘Lorne’) is checked. If not true, the third and final condition (‘Kirstie’) is
checked. If none of these is true, the ‘Hello stranger’ message is printed.
31
VB.Net uses If, ElseIf, Else and End If keywords. Indentation is optional and a single
equals (=) is used to compare if values are equivalent.
'VB.Net
name = Console.Readline()
If name = "George" Then
Console.WriteLine("Hello George")
ElseIf name = "Lorne" Then
Console.WriteLine("Great work Lorne")
ElseIf name = "Kirstie" Then
Console.WriteLine("Nice to see you again")
Else
Console.WriteLine("Hello stranger")
End If
C# uses if, else if and else keywords. Indentation is optional and a double equals (==)
is used to compare if values are equivalent.
//C#
name = Console.Readline();
if (name == "George")
{
Console.WriteLine("Hello George");
}
else if (name == "Lorne")
{
Console.WriteLine("Great work Lorne");
}
else if (name == "Kirstie")
{
Console.WriteLine("Nice to see you again");
}
else
{
Console.WriteLine("Hello stranger);
}
With the above example, the program will always have one path to follow. It is important to
note that the conditions are checked in the sequence given.
32
Worked example
OUTPUT 'Enter a score out of 20'
mark ← USERINPUT
IF mark > 5 THEN
OUTPUT 'Could do better'
ELSE IF mark > 10 THEN
OUTPUT 'Average mark'
ELSE IF mark > 15 THEN
OUTPUT 'Excellent'
ENDIF
What would happen if someone here got a mark of 19 out of 20? Unfortunately, the
message ‘Could do better’ would be displayed as 17 is larger than 5 and so the first
condition is true. The other conditions will not be checked.
The solution to this problem would be to change the sequence of the conditions so that
the highest mark is checked first.
Worked example
Key point
FOR p ← 1 TO 10
Iteration can be definite OUTPUT p * 8
(count-controlled) or ENDFOR
indefinite (condition-
controlled). Definite Start
iteration repeats a set
number of times (e.g. p=1
‘repeat this code 5 times’)
whereas indefinite iteration print
repeats based on a Boolean (p * 8)
condition.
p=p+1
Is No
p = 10?
Yes
End
Both the program code and flowchart will print out the values 8, 16, 24 and so on, up to and
including the final value 80.
33
Using the FOR loop shown so far, the programmer defines exactly how many times the given
Key point
code will repeat.
A FOR loop will
automatically increment
Examples in high-level languages – FOR loops
the value of the counter Python repeats using the RANGE keyword. Uniquely, the number given controls how many
variable by 1 each time; times the loop iterates, but the values will start at 0. The code below will therefore print out 0 to 9.
there is no need to do this
manually. for x in range(10):
print(x)
VB.Net uses syntax very similar to the AQA Pseudo-code. The following code will print out
0 to 9.
For x = 0 To 9
Console.WriteLine(x)
Next x
C# uses a for loop that has three parts: the initialisation of the counter variable, the condition
to check whether to repeat again, and the step to increase the counter variable by 1 each time
(in this case ++ meaning to add one to the variable). The following code will print out 0 to 9.
Indefinite loops
Indefinite iteration instead checks a condition each time around the loop to decide whether
to repeat the loop again or continue. For this type of iteration, the programmer will not know
how many times the code will repeat.
AQA Pseudo-code, VB.Net and C# provide two types of indefinite iteration – WHILE loops
and REPEAT UNTIL loops. These both perform a similar task but differ in when the condition
is checked and whether the condition needs to be True or False to repeat again. Python only
provides a WHILE loop.
Note that the WHILE loop will repeat while the total is less than 20 whereas the REPEAT
UNTIL loop will repeat until the total is larger than or equal to 20. They are both logically
equivalent and produce exactly the same results but check different conditions at different
times in the code.
Key point
A WHILE loops checks the condition before starting the loop whereas a REPEAT UNTIL loop
checks the condition after the loop has completed. In some circumstances, this could mean that the
WHILE loop will never start but the REPEAT UNTIL loop will always execute at least once.
Both types of loop in the example above will run infinitely if the user simply repeats typing in
negative values.
34
VB also has a LOOP WHILE statement (where the condition is checked at the end of the loop)
and also a DO WHILE loop, which is functionally equivalent to a WHILE loop.
C# has a WHILE loop in the same way that Python and VB.Net do. C# does not have a DO
UNTIL loop, but it has a DO WHILE loop, which can be used in an equivalent way.
The two C# examples given above are functionally equivalent, apart from where the condition
is checked. The first example will check before beginning the first iteration whereas the second
example is not checked until the loop has run at least once.
35
Worked example
OUTPUT 'Enter an even number up to 100'
num ← USERINPUT
IF num > 100 THEN
OUTPUT 'That is too large'
IF num MOD 2 ≠ 0 THEN
OUTPUT 'It isn’t an even number either!'
ENDIF
ENDIF
The code will first check if the number is above 100 and output a warning message if this is
the case. However, another IF statement is then nested inside this to give another warning
message if the number is not even. Notice that if an odd number over 100 is entered, both
warning messages are displayed, but if an odd number below 100 is entered, nothing is
displayed; this differentiates it from simply using separate IF or ELSE IF statements. The
nested IF statement is only checked if the first one is True.
Worked example
FOR a ← 1 TO 4
FOR b ← 1 TO 3
OUTPUT a * b
ENDFOR
ENDFOR
In this example, the outer loop will repeat four times, but each of these repetitions involves
three executions of the inner loop. This code will therefore produce 12 lines of output
(4 × 3 = 12). WHILE loops can be nested in exactly the same way.
Worked example
age ← 0
WHILE age < 18
OUTPUT 'Enter your age'
age ← USERINPUT
IF age = 17 THEN
OUTPUT 'You cannot vote but you can drive a car'
ELSE IF age = 16 THEN
OUTPUT 'You cannot vote but you can drive a
moped'
ELSE IF age < 16 THEN
OUTPUT 'Sorry, you are too young to vote or drive'
ELSE
OUTPUT 'Congratulations, you can vote and drive'
ENDIF
ENDWHILE
In this example, the code checks whether the user can vote (if they are aged 18 or over) or
drive (if they are aged 17 or 16). This is all nested inside a WHILE loop that repeats while the
36 user’s age is under 18.
Knowledge check
2 State the three basic program constructs and describe each one.
3 What is the difference between a WHILE loop and a REPEAT UNTIL loop?
r = score % 2 #modulus
37
r = score % 2; //modulus
For division, the ‘/’ operator is used, but the output depends on whether the values given are
defined as integers or real numbers. If integers are divided then the answer will always be an
integer and the operation is integer division. If real numbers are divided then the answer will
always be a real number and the operation is normal division.
This is also the case for Python prior to version 3.
Operator precedence is the same as in GCSE Mathematics, with BIDMAS being important.
Tech terms Any operators in brackets are applied first, with indices next, then division and multiplication,
Operator precedence then addition and subtraction last.
The order in which
operations are carried Worked example
out.
For example, (3 + 6) + 7 * 2 means that the (3 + 6) is completed first, with the multiplication
BIDMAS
(7 * 2) completed next and then the results of these added together:
This stands for Brackets,
Indices, Division, (3 + 6) + 7 * 2
Multiplication, Addition =9+7*2
and Subtraction and = 9 + 14
is the order in which = 23
mathematical operations This gives the answer of 23. If the calculation was (incorrectly) carried out sequentially then
should take place if no this would give the wrong answer of 32.
other information is
provided.
Key point
The MOD operator can be used to decide if a number is odd or even. If we hold a value in the
variable num, then num MOD 2 will give 0 if the value is an even number and 1 if the value is an odd
number. It can also be used in the same way to decide if a number is an exact multiple of another
smaller number.
39
Worked example
OUTPUT 'enter your username'
username ← USERINPUT
OUTPUT 'enter your password'
password ← USERINPUT
IF username = 'admin' AND password = 'changeme123' THEN
OUTPUT 'Correct details. Logged in'
ELSE
OUTPUT 'Incorrect details'
ENDIF
In this example, the AND operator means that both conditions (the username and
password both matching the correct ones) need to be True for the user to be logged in.
The OR operator requires one or the other (or both) of the conditions to be True for the
overall condition to be True. If both of the conditions are False, the overall condition will be
False.
Worked example
num1 ← USERINPUT
num2 ← USERINPUT
IF num1 > 10 OR num2 > 10 THEN
OUTPUT 'Accepted'
ELSE
OUTPUT 'Rejected'
ENDIF
In this example, the OR keyword means that either of the entries needs to be over 10 for
the ‘Accepted’ message to be displayed. If both are over 10 then the accepted message is still
displayed. The ‘Rejected’ message is only displayed if neither of the two entries is over 10.
Key point
Each condition given to an AND or OR operator must be a full condition. A very common mistake
is to write code such as:
IF num1 OR num2 > 10 THEN
This is incorrect; the first condition (num1) has nothing to be compared against and so this code
will not work as intended. The correct way, to write this is:
IF num1 > 10 OR num2 > 10 THEN
40
The NOT operator reverses the True or False outcome from a comparison.
Worked example
num1 ← USERINPUT
num2 ← USERINPUT
IF NOT(num1 = num2) THEN
OUTPUT 'the numbers are not the same'
ENDIF
In this example, the equivalence operator (=) would give a True outcome if the input values
were the same. However, the NOT operator reverses this, so that a False is returned if the
numbers are the same and True if they are not the same.
Of course, this is logically the same as using the ≠ operator.
C# uses the following Boolean operators, which are considerably different from the AQA
Pseudo-code:
a & b //AND
a | b //OR
!a //NOT
Knowledge check
4 What is the value assigned to the variable x in each of the following?
(a) x ← 23 – 4 * 3
(b) x ← (12 – 5) * 3
(c) x ← 6 * 2 / 3
(d) x ← 8 / (5 – 1)
(e) x ← 19 MOD 5
(f) x ← 22 MOD 4 * 2
(g) x ← 28 DIV 6
(h) x ← 23 DIV 2 * 4
5 What will be returned by the following comparisons?
(a) a ≠ b if a = 8 and b = 5
(b) a ≥ b if a = 9 and b = 5
(c) a > b OR c < d if a = 5, b = 5, c = 3, d = 2
(d) a ≤ b AND c ≠ d if a = 6, b = 6, c = 2, d = 4
41
1-dimensional arrays
A 1-dimensional array (1D) is accessed via a single numeric index value.
Array index 0 1 2 3
Tech term Data ‘Fletcher’ ‘Imogen’ ‘Tia’ ‘Muhammad’
The above 1D array can be created using the following code in AQA Pseudo-code
Index value
A number that Students ← ['Fletcher', 'Imogen', 'Tia', 'Muhammad']
corresponds to the
location of an item of Note that the array index starts at 0, so an array of 10 values would have indexes from 0 to 9.
data in an array.
Key point
Python does not have simple arrays. Instead, it uses another data structure concept called a list.
Lists are similar in operation but have two key differences. First, lists can contain a mix of different
data types. Second, lists are not of a fixed size and can be added to or reduced in size during the
running of the program.
Arrays are commonly used with FOR loops to access each item in the array in turn. The code
below uses a FOR loop to add up each element in an array called scores, which has already been
set up, where the array has eight items.
Array index 0 1 2 3 4 5 6 7
Data 5 7 0 10 8 3 7 3
total ← 0
FOR i ← 0 TO 7
total ← total + scores[i]
ENDFOR
OUTPUT total
This code would return a total of 43.
VB.Net uses the following syntax. Note that an array is initially defined using {curly braces} but
then is accessed using (brackets).
scores = [5,7,0,10,8,3,7,3]
total = 0
for item in scores:
total = total + item
print(total)
2-dimensional arrays
A 2-dimensional (2D) array is accessed using two index numbers. It can be represented using
a table as shown here:
43
Worked example
To access each element in this 2D array, the following nested FOR loops could be used.
FOR x ← 0 TO 2
FOR y ← 0 TO 3
OUTPUT scores[x][y]
ENDFOR
ENDFOR
This code accesses the [0][0] entry first, then the [0][1] entry, then [0][2], then [0][3]; then
[1][0], [1][1], [1][2] and so on up until the final [2][3] entry.
Key point
There is no one ‘correct’ way to represent a 2D array; it can be thought of as being accessed via [row]
[column] or [column][row]. A table is simply an abstract representation of how the data is stored in
a 2D array. Any exam question using a table for this will tell you how to access the array.
VB.Net uses the following syntax, with each element accessed by two index numbers in
brackets separated by a comma.
For x = 0 To 2
For y = 0 To 3
Console.WriteLine(scores(x,y))
Next y
Next x
C# uses the following syntax, with square brackets used and a comma to separate the index values.
for (int x = 0; x < 3; x++)
{
for (int y = 0; y < 4; y++)
{
Console.WriteLine(scores[x,y]);
}
44 }
Knowledge check
6 The contents of the array fruit is displayed below, where fruit[1][3] is ‘Apple’.
0 1 2 3 4
0 Pear Grape Banana Damson Orange
1 Raspberry Blueberry Blackcurrant Apple Grapefruit
2 Strawberry Greengage Lemon Lime Kiwi
(a) What is the value of fruit[1][1]?
(b) What is the value of fruit[2][3]?
(c) What is the array element for ‘Blackcurrant’?
● Surname
● YearGroup
● Email.
We can then store data under these field names in a database management system using a
table.
Table 2.2 Table called 'Student' showing three records
FirstName Surname YearGroup Email
Bradley Jenkins 9 [email protected]
Ghita Cable 10 [email protected]
Charlotte Pegg 9 [email protected]
Worked example
To define the record structure shown above, we could use the following code:
RECORD Student
FirstName: String
Surname: String
YearGroup: Integer
Email: String
ENDRECORD
45
Worked example
The following program in AQA Pseudo-code calculates the circumference of a circle using
pi and user input before outputting the answer.
constant pi ← 3.14159
radius ← USERINPUT
circumference ← 2 * pi * radius
OUTPUT circumference
Note that C# does not have specific tools for converting to and from ASCII, but rather an
ASCII value is implicitly returned or used when converting between a char and an integer.
Concatenation
Concatenation of strings means to join multiple strings together. This is done using the +
operator. When strings are concatenated, they are joined together in the order given.
Worked example
texta ← 'this is a message'
textb ← 'great string'
new ← 'GCSE ' + SUBSTRING(5,6,texta) + ' ' +
SUBSTRING(0,4,textb)
OUTPUT new
The above code would join together extracts from the two strings to give ‘GCSE is great’.
47
Key point
The + operator is ‘overloaded’, which means that it does different things depending on what data is
given to it. Compare the result of 2+7 (which gives 9) with the result of “hello”+”world” (which gives
“helloworld”). The + operator concatenates strings but adds numeric values.
String/type conversion
Type conversion (sometimes referred to as casting) means to convert data from one data
type to another. String conversion means converting another data type to or from the
Key point string data type. To do this, the following keywords are used in AQA Pseudo-code:
Note that some languages Keyword Examples Comment
such as Python also allow STRING_TO_INT() a ← STRING_TO_INT('123') Converts a value stored as a string
programmers to treat b ← STRING_TO_INT('7') to an integer.
a string as an array of
characters and extract STRING_TO_REAL() c ← STRING_TO_REAL ('12.9') Converts a value stored as a string
individual characters this d ← STRING_TO_REAL ('46') to a real/floating point number.
way. This would be an INT_TO_STRING() e ← INT_TO_STRING(17) Converts a value stored as an
acceptable alternative in f ← INT_TO_STRING(140) integer to a string.
examination questions. REAL_TO_STRING() g ← REAL_TO_STRING(17.2) Converts a value stored as a real/
h ← REAL_TO_STRING(3.8) floating point number to a string.
Not all values can be converted to another data type. For example, if a programmer attempted
Tech term to convert the string ‘hello’ to an integer value using
Casting newval ← STRING_TO_INT('hello')
Changing one data type an error would be raised. There is no sensible way of deciding what integer value ‘hello’ should
to another. be converted to.
48
Note that in VB.Net and C#, the ‘single’ data type is another name for float/real. (There is also
a double data type that uses twice as many bits of storage and therefore increases precision.)
Knowledge check
7 If text ← 'Computing is fun', what is returned by:
(a) LEN(text)
(b) SUBSTRING(0,1,text)
(c) SUBSTRING(8,LEN(text)-1),text)
(d) What command returns the string ‘fun’?
Worked example
r ← RANDOM_INT(1, 10)
49
import random
print(random.randint(1, 100))
VB.Net uses the following syntax to pick a random value between 1 and 100:
Dim r As Random = New Random
Console.WriteLine(r.Next(1, 101))
C# uses the following syntax to pick a random value between 1 and 100:
Main program
running
Subroutine called
Subroutine runs
Main program
continues
50
Defining subroutines
A subroutine is a section of code that is defined outside the main body the program. It is given
its own identifier, which is then used to call the subroutine as many times as required.
#subroutine definition
SUBROUTINE timestableuser()
OUTPUT 'enter times table'
num ← USERINPUT
FOR x ← 1 TO 10
OUTPUT num * x
ENDFOR
ENDSUBROUTINE
Here, a subroutine to produce a printed times table is defined once and given the identifier
timestableuser. Once defined, the subroutine can be called from within a program as
many times as required.
Passing parameters
Note the use of brackets after the subroutine’s identifier. In the last example, these brackets
were empty but they can be used to pass parameters into the subroutine.
A parameter is a value that the subroutine will use. We can rewrite the previous subroutine
with parameters to control which times table will be produced and how many numbers to
print out.
Worked example
#subroutine definition with parameters
SUBROUTINE timestable(tt, nums)
FOR x ← 1 TO nums
OUTPUT tt * x
ENDFOR
ENDSUBROUTINE
Another subroutine is defined, called timestable . This time it expects two parameters
to be passed into the subroutine in the form of variables tt and nums. When the
subroutine is called, these parameter values also have to be passed in as part of the
subroutine identifier.
In this example, the first time the subroutine is called the values 8 and 10 are passed into the
subroutine. The second time the subroutine is called, the values 9 and 12 are passed into the
subroutine. The first call will print out the 8 times table from 8 × 1 to 8 × 10 whereas the
second call will print out the 9 times table from 9 × 1 to 9 × 12.
Using this subroutine is far more flexible and efficient than writing new code for each
different times table.
51
Worked example
#subroutine definition that returns a value
SUBROUTINE circle_area(radius)
const pi ← 3.14159
area ← pi * radius^2
RETURN area
ENDSUBROUTINE
def circle_area(radius):
PI = 3.14159
area = PI * radius**2
return area
VB.Net uses the following syntax to define a subroutine that returns a value:
Note, in both VB.Net and C# the subroutine definition may appear very differently, depending
on whether data types and the scope of the subroutine are declared.
Local variables
In the circle_area() subroutine used previously, the values area and pi are both used
within the subroutine definition. However, these variables have local scope. This means that
these variables only exist within the subroutine and cannot be accessed by the main program.
Such variables are called local variables.
If a user attempts to access one of these variables from the main program in a high-level
language, an error will occur.
Worked example
Here, the circle_area subroutine has been defined in Python and then called by
passing a radius of 10 in as a parameter. The programmer has also tried to print the value of
the local variable area .
def circle_area(radius):
PI = 3.14159
area = PI * (radius**2)
return area
print(circle_area(10))
print(area)
However, attempting to print the local variable area will result in an error as the variable
does not exist outside the subroutine. The exact same issue occurs in VB.Net and C#.
print(area)
NameError: name 'area' is not defined
The main advantages of the structured approach to programming include the following:
● It reduces the overall size of the program as code does not need to be repeated in multiple places.
● It makes the code much easier to maintain as it is easier to read and understand the
purpose of each subroutine.
● It reduces development and testing time as code is much easier to write and debug.
● It allows reuse of code between programs, especially where pre-written and pre-tested
subroutines can be used.
A function is a subroutine that returns a value. A procedure is a subroutine that does not
return a value.
Worked example
Example A Example B
price1 ← 100 * 1.2 SUBROUTINE calculate(price)
OUTPUT 'the price is £' newprice ← price * 1.2
OUTPUT price1 RETURN 'the price is £' +
newprice
price2 ← 87 * 1.2 ENDSUBROUTINE
OUTPUT 'the price is £' OUTPUT(calculate(100))
OUTPUT price2 OUTPUT(calculate(35))
OUTPUT(calculate(87))
price3 ← 35 * 1.2
OUTPUT(calculate(17))
OUTPUT 'the price is £'
OUTPUT price3 OUTPUT(calculate(99))
price4 ← 17 * 1.2
OUTPUT(calculate(400))
OUTPUT 'the price is £'
OUTPUT price4
price5 ← 99 * 1.2
OUTPUT 'the price is £'
OUTPUT price5
Both of the examples above take six prices and add 20% in tax before printing the value.
However, Example A achieves this through copying and pasting the code whereas Example B
uses a subroutine.
Example B is not only shorter but is much easier to follow through. Crucially, if the tax rate
changes from 20%, it only needs to be changed in one place in Example B. This makes the
program much easier to maintain.
Example B utilises a modular approach where the calculate() subroutine accepts a
parameter for the price to be used, has a local variable newprice and then returns the
overall calculation result rather than printing it.
Knowledge check
8 Describe one difference between a function and a procedure.
9 Describe two benefits of using subroutines.
54
Worked example
The following is a program for a banking application that allows the user to withdraw
money from their account.
balance ← 100
withdraw ← USERINPUT
balance ← balance - withdraw
OUTPUT 'your balance is now' + balance
We could check that this program works if the balance is £100 by withdrawing £20,
expecting to see a balance of £80 remaining.
However, if we check for robustness, some potential issues become clear:
➤ Should we be allowed to withdraw more than our balance?
➤ What if we withdraw a negative balance? This will effectively add money to our account.
➤ What if the user enters an amount in words, such as ‘TEN POUNDS’? Will this cause the
program to crash?
➤ What if the user enters numbers with the preceding £ sign? Will this cause the program
to crash?
All of these issues would need to be dealt with by the programmer before the program
could be said to be robust.
Data validation is the process of checking input data against rules defined by the
programmer to ensure that the data is sensible and as expected.
Key point
Validation cannot check that data is correct, only that it follows certain rules. For example, a
programmer could validate that a phone number entered by the user is made up entirely of
numbers and starts with a 0. If a phone number of 123ABC was entered, this would be rejected as
invalid. However, if a user entered a valid phone number but mistakenly entered the wrong digits,
such as someone else’s phone number, the program would not identify this.
55
Worked example
The following program shows the previous banking application program, but this time
the input has been partially validated. The user cannot enter a value below 0 and cannot
withdraw more than their current balance. The WHILE loop ensures that they are
continually asked for a withdrawal amount until the value entered is validated successfully.
balance ← 100
withdraw ← 0
WHILE (withdraw ≤ 0) OR (withdraw > balance)
OUTPUT 'Enter amount to withdraw in £'
withdraw ← USERINPUT
IF withdraw < 0 THEN
OUTPUT 'You must withdraw a positive amount'
ELSE IF withdraw > balance THEN
OUTPUT 'You cannot withdraw more than your balance'
ENDIF
ENDWHILE
balance ← balance – withdraw
OUTPUT 'Your balance is now'
OUTPUT balance
Of course, there would be more to do to fully validate the input because the user can still
leave the input amount blank or enter a non-numeric value.
56
Knowledge check
10 State what is meant by validation.
11 Suggest two rules that could be used to validate a date of birth entered by a user.
12 Explain why someone’s name could not easily be validated.
13 In the validated code in the worked example above, write down what happens in each
line of code when the user enters:
(a) −10
(b) 110
(c) 60
Authentication
Some computer systems, such as online shopping websites, are available to all users on an
anonymous basis. Users can search for products without giving any personal details. However,
in order to do any more than this, users are often required to be authenticated. Some computer
systems require authentication to be allowed to use the system at all.
Authentication is the process of establishing a user’s identity. How can the computer system
be sure that the user is who they say they are? Users can be authenticated in many ways:
● Usernames and passwords are perhaps the most common method. A username and a
secret password are chosen by the user and when these are entered, a computer system
can check that they match those of a known user.
● Possession of an electronic key, device or account can be used for authentication since
only one person will have access to that particular device. Some computer systems will
check that an email address or phone number belongs to you by sending an email or text
containing a secret code.
● Biometrics is the use of measurements relating to biological traits. If your school uses
fingerprint scanners to identify you, you will have experience of this. Banks are increasingly
using voice recognition to authenticate users who use telephone services.
For example, the following pseudo-code will only allow entry if a username and password are
both entered correctly:
username ← 'admin'
pwhash ← '5fa345bcd3c1'
OUTPUT 'enter a username'
un ← USERINPUT
Tech term OUTPUT 'enter password'
pw ← USERINPUT
Two-factor IF un = username AND hash(pw) = pwhash THEN
authentication loggedin ← True
Establishing a user’s ELSE
identity by means of loggedin ← False
ENDIF
two separate methods,
such as passwords and Two-factor authentication is where two of the above are checked simultaneously.
biometrics. For example, you may log in to a system with a username and password (first method of
authentication) and are immediately then sent a text message or email to respond to (second
method of authentication).
57
Testing
No matter how well written a program is, there is always the chance that errors have crept
in. Testing allows us to systematically check that a program functions as it should in all
circumstances.
The purpose of testing is to ensure that the program functions as expected and meets all
Tech terms requirements. However, testing should also be destructive; that is, we should not simply aim
Destructive testing to prove that the program works, but we should also try to do all we can to break it. Only by
Instead of simply knowing that it cannot easily be broken can we be satisfied that it works fully.
checking whether For instance, if we create a program for a hot drinks machine that should give us a selection of
a program works as drinks for £1 each, is it enough to test it by inserting £1 and pressing the corresponding drink?
intended, destructive This is a starting point, but if we only relied on this test we may not realise that someone is able
testing actively tries to to get a drink without inserting any money. Only by testing it destructively, and trying to see
find ways to break the if there is any other way of getting a drink for less than £1, can we be sure that it works fully.
program.
Test plan Selecting test data
A list of test data,
To test a program effectively, a test plan is needed. This plan lists all of the tests that will be
expected and actual
carried out, the test data to be used and the expected outcome. Test data should cover as
results.
many of the following situations as possible.
Normal
Normal (or typical) test data is data of the correct type that would be expected from
a user who is correctly using the system. This should be accepted by the program without
causing errors.
58
Boundary
Boundary (or extreme) test data is data that is of the correct type but is on the very edge
of being valid. Boundary test data should be accepted by the program without causing errors.
Erroneous
Erroneous test data is data that should be rejected, either because it is outside the
expected values or because it is of the incorrect type. For example, if a program expected
a numeric input between 1 and 10, both the value 25 and a string such as ‘hello’ would be
erroneous inputs.
Consider this example: A system allows a user to enter a value between 0 and 100, with the
number being rounded up or down to the nearest 10. Any numbers outside the range 0 to 100
should be rejected.
There are many possible tests but a typical test plan could be as shown in the table below.
Test data Type of test data Reason Expected result
Key point 47 Normal To check if values round up 50
32 Normal To check if values round down 30
Test data should be listed 0 Boundary To check the low boundary 0
on a test plan using the 100 Boundary To check the high boundary 100
actual data that would be -5 Erroneous To check if numbers below 0 are rejected Rejected
entered. A very common 150 Erroneous To check if numbers above 100 are rejected Rejected
mistake is to simply describe
“Twelve” Erroneous To check data of the wrong type is rejected Rejected
the test data (such as ‘a
number larger than 100’).
This is not specific enough;
instead an actual value (e.g.
101) should be included in
Knowledge check
the test plan. 17 State what is meant by normal test data.
18 Describe how boundary test data is different from erroneous test data.
19 A system should allow passwords that are between 8 and 15 characters in length.
Suggest one suitable item of erroneous test data for this system.
20 Complete the following test plan for a system that checks if users are 18 years of age
or older. Anyone younger than 18 should be rejected. Anyone 18 or over should be
accepted.
59
Worked example
The code below should allow values between 1 and 10.
OUTPUT 'Enter a value between 1 and 10'
num ← USERINPUT
IF num > 1 AND num < 10 THEN
OUTPUT 'Allowed'
ELSE
OUTPUT 'Not allowed'
ENDIF
When this code is tested thoroughly, a number of errors are discovered. These are shown in
the test plan below.
Test data Type of test data Reason Expected result Actual result
5 Normal Check valid data Allowed Allowed
1 Boundary Check low Allowed Not Allowed
extreme of range
10 Boundary Check high Allowed Not Allowed
extreme of range
0 Erroneous Check low Not allowed Not allowed
outside range
11 Erroneous Check high Not allowed Not allowed
outside range
The code can then be refined to ensure that it works on these boundaries and then tested
again.
OUTPUT 'Enter a value between 1 and 10'
num ← USERINPUT
IF num ≥ 1 AND num ≤ 10 THEN
OUTPUT 'Allowed'
ELSE
OUTPUT 'Not allowed'
ENDIF
This refined code should then be tested again using suitable test data. Depending on the
changes that were made to the code, new test data might need to be selected – do not
assume you can simply use the same test plan.
60
Worked example
The code below contains a number of syntax errors.
num ← USERINPTU
10 ← x
OUTTPU num + x
Firstly, the USERINPUT statement on the first line is misspelled as USERINPTU. Next, the
assignment statement on the second line is the wrong way around (it should be x ← 10).
Lastly, the keyword OUTPUT has been misspelled as OUTTPU. Any one of these errors
would stop the program from running and produce a syntax error.
A logic error by comparison is an error in the algorithm that does not stop the program
from running but means it does not always produce the correct output. This is usually caused
by the programmer writing instructions that have the correct syntax but do not do what was
intended.
Worked example
The code below contains a logic error.
SUBROUTINE addup(a, b)
RETURN a * b
ENDSUBROUTINE
The intention of the subroutine is to add up the two numbers passed in as parameters.
However, the subroutine instead multiplies the two numbers. This is a valid instruction
and would not cause the program to stop, but it is certainly not what the programmer
intended.
Note that a logic error in the code does not necessarily mean that the program always
produces an incorrect output – it may only occur in some parts of the program, or only when
certain inputs are used.
Key point
Syntax errors are errors relating to the rules of the programming language. A program containing a
syntax error will not run and hence it is clear that there is an issue with it. Programs containing logic
errors do run but do not produce the desired output. Logic errors are harder to spot because it is
not always immediately clear that there is an issue with the program.
Knowledge check
21 Give one difference between a logic error and a syntax error.
22 A programmer writes the line IF x > FOR . Explain whether this would cause a logic
or a syntax error.
23 A programmer finds that a subroutine to calculate values does not output the result
expected when negative values are passed in as parameters. Explain whether this would
cause a logic or a syntax error.
61
62
False
Condition
True
Iteration
Iteration is used to repeat sections of code. Iteration is
commonly called looping.
63
Definite iteration repeats code a defined number of times. FOR loops can be used to
implement count-controlled iteration. A step can also be defined. For example:
FOR p ← 1 TO 10
OUTPUT p * 8
ENDFOR
Indefinite iteration checks a condition each time around the loop and decides whether to
repeat the code again or continue. WHILE loops and REPEAT UNTIL loops can be used to
implement condition-controlled iteration.
WHILE loop REPEAT UNTIL loop
total ← 0 total ← 0
WHILE total < 20 REPEAT
num ← USERINPUT num ← USERINPUT
total ← total + num total ← total + num
ENDWHILE UNTIL total ≥ 20
OUTPUT 'done!' OUTPUT 'done!'
Note that the WHILE loop will repeat while the total is less than 20 whereas the REPEAT
UNTIL loop will repeat until the total is larger than or equal to 20. They produce exactly the
same results but check different conditions at different times in the code.
64
65
1D and 2D arrays
A 1-dimensional array allows a programmer to store multiple items of data under a single identifier.
Array index 0 1 2 3 4
Data ‘hello’ ‘world’ ‘how’ ‘are’ ‘you?’
The above 1D array can be created using the following code in AQA Pseudo-code:
phrase ← ['hello', 'world', 'how', 'are', 'you?']
A 2-dimensional array allows a programmer to store multiple items of data using two identifiers.
It can be represented in a table form as shown below:
0 1 2 3 4
0 23 83 5 15 64
1 3 92 4 7 5
Any exam question using a table for this will tell you whether you access the array as
[row, column] or [column, row].
Lists
Python does not have simple arrays. Instead, it uses another data structure concept called a
list.
Lists are similar in operation to arrays but have three key differences.
■ Lists can contain a mix of different data types.
■ Lists are not of a fixed size and can be added to or reduced in size during the running of the
program.
■ There is no such thing as 2D list – however, you can create lists within lists that perform the
66
Concatenation
■ Concatenation means joining multiple strings together.
■ This is done using the + operator. When strings are concatenated, they are joined together in
the order given:
texta ← 'two'
textb ← 'words'
new ← texta + textb
OUTPUT(new)
The above code would join together the two strings to print out ‘twowords’.
String/type conversion
■ String conversion (or casting) means to convert data from or to the string data type.
The following keywords are used in AQA Pseudo-code:
67
68
Local variables
■ Variables used in the subroutine are called local variables.
■ Local variables only exist within the subroutine and cannot be called by the main program.
■ It is good practice use local variables because any errors associated with them will be limited
to the subroutine rather than across the whole program – this makes code easier to debug.
69
■ Reduces development and testing time as code is much easier to write and debug.
■ Allows reuse of code between programs, especially where pre-written and pre-tested
subroutines can be used.
A function is a subroutine that returns a value. A procedure is a subroutine that does not
return a value.
Robust and secure programs can be written using the following techniques.
Data validation
This is used to ensure that users have entered data in the correct form, for instance:
■ of the correct type
■ within a sensible range
■ of the correct length
■ not empty.
Authentication
This is used to ensure that only authorised users access a system by establishing a user’s
identity. This can be one in a number of ways:
■ using usernames and passwords
■ through possession of an electronic key, device or account
■ using biometrics.
Two-factor authentication is where two of the above are checked simultaneously.
Testing
■ The purpose of testing is to ensure that the program functions as expected and meets all
requirements.
■ Testing should not simply aim to prove that the program works, but also try to break it. Only
70
■ Boundary test data is test data that is of the correct type but is on the very edge of being
valid. Boundary test data should be accepted by the program without causing errors.
■ Erroneous test data is test data that is outside the expected values or of the incorrect type,
and should be rejected by the system.
A test plan lists all of the tests that will be carried out, the expected result and the actual
result in each case. For example:
Test data Type of test data Reason Expected result Actual result
Normal
Boundary
Erroneous
A syntax error is one that breaks the grammatical rules of the programming language.
Examples include misspelling a keyword, missing a bracket or using a keyword in the wrong way.
Syntax errors will stop the program from running.
A logic error is one that causes the program to produce an unexpected or incorrect output but
will not stop the program from running.
71
01.3 Give one reason why you have identified this item as a variable. [1 mark]
02 Alisha is writing a program to say whether or not someone is old enough to vote.
The program needs to perform the following tasks:
• Input an age from the user.
• Compare the number to 18 and output either “Old enough to vote” or “Too young
to vote”.
age ← USERINPUT
………………………………………………………………
ELSE
………………………………………………………………
ENDIF
02.2 Identify two basic programming constructs that have been used in this
algorithm. [2 marks]
72
FOR k ← 1 TO 4
OUTPUT (i * 2) + k
ENDFOR
ENDFOR
03.1 Give the first three numbers that will be printed by this algorithm. [1 mark]
03.2 Tick () one box in each row to identify whether each programming
construct has or has not been used in this program. [3 marks]
Has been used Has not been used
Sequence
Selection
Iteration
03.3 Line 3 of the program is changed to OUTPUT i - k. Give the first three numbers
that will now be printed. [1 mark]
05 Bob is writing a program to calculate the area of a circle using the formula:
area = π * r2
The program needs to perform the following tasks:
• Input a whole number from the user.
• Repeat bullets 1 and 2 if the user enters a number that is too large or small.
05.2 Identify one item in the program that could have been written
as a constant. [1 mark]
05.3 Give one reason why you have identified this item as a constant. [1 mark]
06 A computer system stores data about train journeys, including the destination, cost,
number of changes needed and whether first class seating is available.
Destination Cost (£) Number of changes First class
Birmingham 120.00 0 TRUE
London 75.60 1 TRUE
Liverpool 98.40 3 FALSE
Newcastle 143.50 2 FALSE
Edinburgh 174.00 2 TRUE
Identify a suitable data type for each field and justify your choice. [8 marks]
Destination:
Cost:
Number of changes:
First class:
07 The following shows values stored in an array called fruit at the start of a process:
0 1 2 3
0 Apple Cherry Banana Pear
1 Lemon Orange Raspberry Damson
2 Grape Pineapple Peach Plum
07.3 Redraw the table after the following series of commands has been executed:
fruit[0][0] ← 'Lime'
fruit[2][0] ← 'Strawberry'
fruit[2][2] ← '
'
[3 marks]
74
08 Gill is writing a program to calculate an employee’s weekly pay. It requires the user to
input the number of hours worked in a week and the hourly rate of pay.
Describe two examples of robust programming that Gill should consider
when writing her program [4 marks]
09 The program below should only allow values from 1 to 100 as valid inputs. If the data
entered breaks this validation rule an error message is displayed.
mins ← USERINPUT
ENDIF
09.2 Explain what is meant by data validation. [1 mark]
10 10.1 U
sing either AQA Pseudo-code or a high-level programming language,
write a program to authenticate a user. [7 marks]
• When the username and password are correct say “Access Granted”.
75
11 The following program takes two numbers as inputs from the user and then says which is
the biggest.
11.1 Explain, using examples from the program, two ways in which the
maintainability of the program can be improved. [4 marks]
12 12.1 W
rite a subroutine that takes a number between 1 and 12 as a parameter
and returns the corresponding month of the year as a string. [5 marks]
13 Raheem is writing a computer program that will take in the base and height of a triangle
as inputs from the user and outputs the area using the formula: area = 0.5(base x height).
14 Olivia has written a program to work out whether a number is a prime number. Her first
attempt is shown below:
14.2 Give a corrected version of line 05 that fixes the error. [1 mark]
14.4 Give a corrected version of line 09 that fixes the error. [1 mark]
14.5 Olivia has been testing her program regularly as she writes it. State the
name given to this type of testing. [1 mark]
15 The program below checks whether a number entered by the user is between
1 and 20. If the number is not within this range an error message is displayed.
OUTPUT 'Enter a number'
userNumber ← USERINPUT
WHILE userNumber < 1 OR userNumber > 20
OUTPUT 'Invalid input'
ENDWHILE
OUTPUT 'Number accepted'
77
15.1 Complete the following test plan for the program above. [3 marks]
Test data Test type Expected result
15 Normal Value accepted
Invalid input
Erroneous
message displayed
Boundary
15.2 Explain the purpose of testing the program in this way. [1 mark]
16 A teacher stores test results for each student in their class in a 2D array. The figure below
shows part of the array, with five students and five sets of test results. The index labels
are also shown.
Student ID
0 1 2 3 4
Test ID 0 15 18 11 12 14
1 9 14 15 10 13
2 14 15 12 11 10
3 18 17 18 16 15
4 11 12 13 12 15
The teacher wants to output the results that student 2 achieved in the last test that
they took (Test ID 4). She writes the following code: OUTPUT testScores[2][4]. The
output is 13.
16.1 Write the code to output the score achieved by student 1 in the second
test that they took. [1 mark]
16.2 State the output if the teacher runs the code: [1 mark]
OUTPUT testScores[0][1]
16.3 State the output if the teacher runs the code: [1 mark]
OUTPUT testScores[3][1] + testScores[4][3]
16.4 The teacher writes a program to work out the average mark achieved by a student
across all five tests.
total ← 0
78
average ← total / 5
OUTPUT average
Refine the program to be more efficient. Write the refined version of the
algorithm using either AQA Pseudo-code or a high-level language you
have studied. [4 marks]
17 The program below gives the grade achieved for an exam mark entered by the user.
m ← 0
WHILE m < 1 OR m > 100
OUTPUT 'Please enter your mark:'
m ← USERINPUT
ENDWHILE
IF m > 80 THEN
OUTPUT 'Grade A'
ELSE IF m > 65 THEN
OUTPUT 'Grade B'
ELSE IF m > 50 THEN
OUTPUT 'Grade C'
ELSE
OUTPUT 'Fail'
ENDIF
17.1 Describe two ways in which the maintainability of this algorithm could be
improved. [4 marks]
17.2 Complete the test plan for the program above. [4 marks]
79
80
81
The column values for base 16 (hex) are based on multiples of 16 so the first two columns are:
16 1
As hexadecimal is base 16, the second column heading is 16 times larger than the first column.
So, a computer needs to understand what the kind of data each binary number represents.
Knowledge check
1 Why do computers work in binary?
2 Why do programmers use hexadecimal?
82
Worked example
What is the binary number 100111 in decimal?
First, copy the binary number 100111 into the table, always ensuring that you fill the table
from the right so that the ‘1’ column is filled with either a ‘0’ or ‘1’:
128 64 32 16 8 4 2 1
1 0 0 1 1 1
We have:
➤ 1 lot of 32
➤ no lots of 16
➤ no lots of 8
➤ 1 lot of 4
➤ 1 lot of 2
➤ 1 lot of 1
This is equal to:
32 + 4 + 2 + 1 = 39
100111 in binary is 39 in decimal.
Notice that the 128 and 64 columns are blank. This is the same as if they contained ‘0’.
Key point
You are expected to be able to work with binary numbers with up to eight digits, that is, 11111111,
but also with values containing fewer than eight binary digits.
To convert decimal numbers into binary we use the column heading values from the binary
table. For each column value, starting at the left-hand side, we decide if it is smaller than or
equal to our decimal number.
If it is smaller or equal to, we record 1 in the table, and subtract that column value from the
original decimal number. We then check if that new number is smaller than the next column
value.
If it is not smaller, we check the original decimal number against the next column, and so on.
We continue this process until we are left with the 1s column.
A worked example will make this clearer.
83
Worked example
Convert the decimal number 142 into binary.
Is 128 smaller than 142? YES, it is, so we record 1 in the first column from the left-hand side.
128 64 32 16 8 4 2 1
1
We continue to check 14. We can see that 32 is not smaller than 14, and neither is 16,
so we can record 0s in the next two columns.
128 64 32 16 8 4 2 1
1 0 0 0
We find that 8 is smaller than 14, and so we put a 1 in the column under 8.
We subtract 8 from 14, leaving 6.
We now check the next column against 6.
4 is smaller than 6. We put a 1 in the column under 4 and subtract 4 from 6, leaving 2.
We now check the next column against 2.
2 is the same as 2 so we put a 1 in the column under 2.
Subtracting 2 from 2, leaves 0.
We have been left to check the number 0 against the last column. No positive number is
smaller than zero, so the final entry is a 0 under the 1 column.
The final table looks like this:
128 64 32 16 8 4 2 1
1 0 0 0 1 1 1 0
We can check our answer by converting the binary number 10001110 back into decimal.
We find that:
10001110 = 128 + 8 + 4 + 2 = 142
We have confirmed that 10001110 is indeed the decimal number 142.
84
Worked example
Convert the decimal number 83 into binary.
We follow the same process as before. 128 is larger than 83 so the entry in the 128 column is 0.
64 is smaller than 83, so we enter a 1 in the column under 64. We also note that 83 − 64 = 19
and we will now check 19 against the next columns.
The next column that is smaller than 19 is 16, so we enter 0 in the 32 column and 1 in the
16 column.
We then note that 19 − 16 = 3 and we will now check 3 against the next columns.
The next column that is smaller than 3 is the 2 column. So we enter a 1 in the 2 column and
note that 3 − 2 = 1.
We check this 1 against the 1 column, and 1 is of course equal to 1. So, we enter a 1 in the
final column.
So, the binary number is:
128 64 32 16 8 4 2 1
0 1 0 1 0 0 1 1
We can check our answer by converting 01010011 back into decimal. We find that:
01010011 = 64 + 16 + 2 + 1 = 83
We have confirmed that 01010011 is indeed the decimal number 83.
Note that we only really need seven binary digits to represent this binary value. So we can
leave the column for 128 blank and give the answer as 1010011. (We do the same thing in
decimal – for instance in this example we could have referred to the number 083. However,
we don’t need the left-hand zero as it doesn’t provide any additional information, and so we
normally drop it and just call the number ‘83’.)
85
Worked example
To convert AF in hexadecimal to decimal
16 1
A F
A is equivalent to 10 and F is equivalent to 15 in decimal.
(10 × 16) + (15 × 1) = 175
AF in hexadecimal is 175 in decimal.
● If it does, we write down how many times using the correct hexadecimal symbol in the 16s
column.
● We then convert the remainder into its hexadecimal symbol and write it in the 1s column.
86
Worked example
Convert 189 in decimal to hexadecimal. You can check this: 11 x 16 = 176
189 divided by 16 = 11 remainder 13. 189 − 176 = 13
The hex symbol for 11 is B.
The hex symbol for 13 is D.
189 in decimal is BD in hexadecimal.
Knowledge check
5 Convert the following decimal values to hexadecimal.
(a) 52
(b) 67
(c) 165
(d) 191
(e) 201
6 Convert the following hexadecimal numbers to decimal.
(a) 12
(b) 58
(c) 5D
(d) AE
(e) CA
87
Consider the binary number 11001110. This can be represented using just two hexadecimal
Key point digits. To do so:
Another name for a 4-bit ● First, split it into two nibbles (4-bit numbers): 1100 and 1110. Each 4-bit binary number
number is a nibble. is equivalent to one hexadecimal symbol. To represent the values 10 to 15 we use A
through to F.
● Now work out the hexadecimal for each 4-bit number.
● In this case, 1100 is equivalent to the decimal number 12, which is the hex number C.
● 1110 is equivalent to the decimal number 14, which is the hex number E.
4-bit binary numbers can represent 16 different values – from 0000 up to 1111, which is 0 to
15 in decimal. Hence any 4-bit binary number can be represented by just one hexadecimal
number 0–F.
Worked example
(a) Converting 11011111 in binary to hexadecimal
The binary number is divided up into two nibbles and the equivalent hexadecimal
symbol identified. This can be done by first converting the binary to decimal if
necessary.
1101 1111
D F
11011111 in binary is DF in hexadecimal.
(b) If we have a binary number with fewer than eight digits, the same process applies. We
split up the number into nibbles (4-bit numbers), starting from the right-hand side.
We add leading 0s to make it up to 8 bits.
For example, using the binary number 1011101:
0101 1101
5 D
1011101 in binary is 5D in hexadecimal.
We use a similar process to convert between hexadecimal and binary; we replace the hex
symbol with the equivalent binary nibble.
88
Worked example
(a) Converting B8 in hexadecimal to binary
B 8
1011 1000
B in hexadecimal is 11 in decimal, which is 1011 in binary.
8 in hexadecimal is 8 in decimal, which is 1000 in binary.
B8 in hexadecimal is 10111000 in binary.
(b) Converting 3A from hexadecimal to binary
3 A
0011 1010
3 in hexadecimal is 3 in decimal, which is 0011 in binary.
A in hexadecimal is 10 in decimal, which is 1010 in binary.
3A in hexadecimal is 111010 in binary.
Knowledge check
7 Convert the following binary numbers to hexadecimal.
(a) 10011100
(b) 110011
(c) 11111111
(d) 111001
(e) 1001110
8 Convert the following hexadecimal numbers to binary.
(a) 95
(b) AB
(c) 1D
(d) A3
(e) 56
Key point
You will be expected to work with and convert between all three number systems in the range:
00–FF in hex
0–255 in decimal
00000000–11111111 in binary.
89
Worked example
For example, if we have a file that is 2.5 MB, what is that in a) kilobytes, and b) bytes?
(a) 2.5 MB = 2.5 × 1000 = 2500 kilobytes
(b) 2.5 MB = 2.5 × 1000 × 1000 = 2 500 000 bytes
Key point
You need to show your working in the examination so show the key multiplications to demonstrate
clearly how you arrived at the answer.
90
Worked example
Adding 357 and 264
3 5 7
7 + 4 = 11
+ 2 6 4 So we write down 1 and carry 1
to be added in the next column.
3 5 7
5 + 6 + 1 = 12
+ 2 6 4 So we write down 2 and carry 1
1 to added in the next column.
1
3 5 7
3+2+1=6
+ 2 6 4 So we write down 6.
2 1
1
3 5 7
+ 2 6 4
6 2 1
So, the key thing to remember is that as soon as a column adds up to a number bigger than
9, we have to carry.
When adding binary numbers, we follow the same process. The difference is that as soon as a
column adds up to a number bigger than 1, we have to carry.
We also need to note that:
1 + 1 = 10 in binary (that is 1 + 1 = 2 in decimal, which is written as 10 in binary)
1 + 1 + 1 = 11 in binary (that is 1 + 1 + 1 = 3 in decimal, which is written as 11 in binary)
To summarise, for binary addition:
Or alternatively:
0 0
+ 0 + 1
0 1
0 0
1 1
+ 1 + 1
0 1
1 1 1
Worked example
Let’s look at an example adding two 4-bit numbers, 1101 and 1111.
1 1 0 1
1 + 1 is 10 in binary so we write
+ 1 1 1 1 down 0 and carry 1 to be added
in the next column.
1 1 0 1
0 + 1 + 1 is 10 in binary so we
+ 1 1 1 1 write down 0 and carry 1 to be
0 added in the next column.
1
1 1 0 1
1 + 1 + 1 is 11 in binary so we
+ 1 1 1 1 write down 1 and carry 1 to be
0 0 added in the next column.
1 1
1 1 0 1
1 + 1 + 1 is 11 in binary so we
+ 1 1 1 1 write down 1 and carry 1 to be
1 0 0 added in the next column.
1 1 1
1 1 0 1
+ 1 1 1 1 The carried 1 is the final
1 1 1 0 0 digit in the sum giving
1 1 1 1
the answer 11100.
We can use the same method to add up binary numbers made of different numbers
of bits.
92
Worked example
Let’s look at adding together three binary numbers made up of a different number of bits:
100101 + 10010 + 10000110
1 0 0 1 0 1
1 + 0 + 0 is 1 in binary so we
1 0 0 1 0 write down 1
+ 1 0 0 0 0 1 1 0
1
1 0 0 1 0 1
0 + 1 + 1 is 10 in binary so we
1 0 0 1 0 write down 0 and carry the 1 to
+ 1 0 0 0 0 1 1 0 the next column
0 1
1
1 0 0 1 0 1
1 + 0 + 1 + 1 is 11 in binary so
1 0 0 1 0 we write down 1 and carry the 1
+ 1 0 0 0 0 1 1 0 to the next column
1 0 1
1 1
1 0 0 1 0 1
We continue this process to
1 0 0 1 0 complete the addition
+ 1 0 0 0 0 1 1 0
1 0 1 1 1 1 0 1
1 1
Key point
In your exam you will be expected to be able to add up to three binary numbers, using a maximum
of 8 bits per number. The sum will never exceed 8 bits.
Knowledge check
Complete the following additions in binary.
9 1100 + 110
10 1011 + 1001
11 110011 + 100101 + 1001
12 110110 + 10101 + 10000000
13 100001 + 11000 + 1000000
93
Binary shifts
Moving the digits in a binary number left or right is called a binary shift.
Multiplication
Each time the value is shifted one place to the left, the number is multiplied by 2.
For example, 40 in binary is 101000:
128 64 32 16 8 4 2 1
1 0 1 0 0 0
If we shift the digits one place to the left, and add 0 to the right-hand 1 column, we get:
128 64 32 16 8 4 2 1
1 0 1 0 0 0 0
The original number that has been moved one place to the left has been highlighted.
In decimal this new number has the value 64 + 16 = 80. This is 40 multiplied by 2.
If we shift another place to the left – which is two places to the left from the original
number – we get:
128 64 32 16 8 4 2 1
1 0 1 0 0 0 0 0
In decimal, this new number is 128 + 32 = 160. This is the original number 40 multiplied by 4.
Division
Each time the value is shifted one place to the right the number is divided by 2.
Starting again with the decimal number 40, which is 101000 in binary, if we shift the digits
one place to the right we get:
128 64 32 16 8 4 2 1
1 0 1 0 0
In decimal, the new number 10100 is 16 + 4 = 20, which is 40 divided by 2.
If we shift another place to the right we get:
128 64 32 16 8 4 2 1
1 0 1 0
In decimal this is 8 + 2 = 10, which is 20 divided by 2 (or the original number 40 divided by 4).
94
Knowledge check
Apply the shifts described to the following binary numbers and state the decimal
equivalents before and after the shift. Comment on what has happened to the value.
14 1100 shift 2 places to the right.
15 11010 shift 1 place to the left.
16 101 shift 3 places to the left.
17 110000 shift 3 places to the right.
18 111 shift 4 places to the left.
19 10000000 shift 4 places to the right.
20 10011 shift 3 places to the left.
21 101100 shift 2 places to the right.
22 What would you need to do to a binary number to a) multiply it by 8, b) divide by 16?
23 What is the effect of shifting left by 3 then right by 2?
ASCII
In 1960, the American Standards Association agreed a set of codes to represent the main
characters used in English. This is called ASCII (American Standard Code for Information
Interchange). This system was designed to provide codes for the following:
All the main characters, i.e. 26 uppercase and 52 characters
26 lowercase
All the numeric symbols 0–9 10 characters
32 punctuation and other symbols plus ‘space’ 33 characters
32 non-printable control codes 32 characters
In total, this is 127 characters. The decimal number 127 is 1111111 in binary, which is a 7-bit
number. This means that each character can be represented by a different 7-bit number, from
0000001 to 1111111. Initially the ASCII character set used 127 codes for the characters, with
0000000 meaning ‘no character’. This gave a total of 128.
95
One additional bit was used for error-checking purposes. This means that each ASCII character
is represented by an 8-bit number and therefore that each character required 1 byte.
Some ASCII codes are:
7-bit binary code Hex Decimal Character
0100000 20 32 ‘space’
1000001 41 65 A
1000010 42 66 B
1000011 43 67 C
1100001 61 97 a
1111001 79 121 y
1111010 7A 122 z
1111111 7F 127 ‘delete’
Unicode
Unicode was first developed to use 16 bits rather than the 7 bits of ASCII. This provided the
ability to store 216 or 65 536 unique characters. Later developments of Unicode used even more
bits to represent billions of different characters, including graphical symbols and emojis. This
allows Unicode to represent many different alphabets and special symbols, which is a major
advantage over ASCII.
To ensure compatibility of all of these systems, the original ASCII character codes are the same
within Unicode. ASCII is now considered to be a subset of Unicode.
The ASCII and Unicode codes for the main alphabetic characters are allocated to the uppercase
characters in sequence, followed by the lowercase characters in sequence. For instance, A is 65,
B is one more at 66, C is next at 67, and so on. This means that if you are given the character
code for one letter, you can work out the character code for another letter.
There are also ASCII codes for the decimal numbers 0–9. These codes also run in order – for
instance, the code for ‘1’ in ASCII is 49, ‘2’ is 50 and so on. If you are given the code for one
number, you can work out the code for another number.
Lowercase characters start with ‘a’ as 97, ‘b’ as 98, and so on. This means that when we sort text,
‘Z’ (which is 90) comes before ‘a’.
For example, if the animals goat, bear, ape, zebra and deer were written as Goat, Bear, ape,
Zebra, deer and sorted using ASCII values, they will be in the order:
Bear, Goat, Zebra, ape, deer
96
Knowledge check
24 If the ASCII value of A is 65 what is the ASCII value of
(a) F
(b) G
(c) J
0 1 0 0 0 0 1 0
0 0 1 0 0 1 0 0
0 1 1 1 1 1 1 0
1 1 0 0 0 0 1 1
1 1 1 1 1 1 1 1
1 0 1 0 0 1 0 1
0 0 1 1 1 1 0 0
1 1 0 0 0 0 1 1
97
Figure 3.1 is just 8 pixels wide by 8 pixels high. As each row is represented by 1 byte, and there
are eight rows, this image requires 8 bytes to store it.
Most images are not ‘blocky’ like this. This is because they are made up of many more pixels.
For instance, the simple black and white drawing in Figure 3.2 is 100 × 152 pixels. This requires
15 200 bits to store it, which is 15 200/8 = 1900 bytes, or just under 2 kilobytes.
11 10 01 00
00 00 00 01 01 00 00 00
00 00 10 01 01 10 00 00
10 10 11 10 10 11 10 10
10 00 01 01 01 01 00 10
10 00 01 01 01 01 00 10
10 00 01 00 00 01 00 10
00 00 01 00 00 01 00 00
00 00 01 00 00 01 00 00
98
The bitmap to represent this image can be seen in the figure and each row can be written down as:
0000000101000000 (top row)
0000100101100000 (second row)
1010111010111010 (third row)
and so on.
With 2 bits for each pixel, we can store 22 = 4 colours.
If we use more bits to represent each pixel, we can represent more colours:
● With 3 bits per pixel, each pixel can be one of 2 = 8 colours. (In binary, these eight codes
3
● With 16 bits per pixel, each pixel can be one of 2 = 65 536 colours!
16
Colour depth is the number of bits used per pixel. The more bits per pixel, the larger the
range of colours we can have in the image. The more colours we have available, the better the
representation of the image. However, the more colours we have, the more bits per pixel we
need. This means that more data is required to store each pixel.
Consequently, the higher the colour depth, the larger the file needed to store the image.
Look at the images in Figure 3.5 of a sign in Portmeirion. The original image has a bit depth of
8, which is 28 or 256 colours, and is 1.2 MB in size. As we reduce the number of colours available
the image become less well defined but the size of the file reduces, to 787 KB for eight colours
and 542 KB for four colours.
Figure 3.5 The same image with 256 colours, eight colours and with just four colours
99
Worked example
For example, what is the file size of an image with an 8-bit colour depth that is 1200 pixels
high and 2000 pixels wide?
File size = 8 × 1200 × 2000 = 19 200 000 bits
We divide by 8 to get this in bytes: 19 200 000/8 = 2 400 000 bytes or 2.4 MB
Knowledge check
25 What do we mean by colour depth?
26 How many colours can be represented using a 4-bit colour depth?
27 If 1 represents black and 0 represents white, draw the 5 × 5 pixel image with the bit
pattern 00100 01010 10001 11111 10001
28 If 1 represents black and 0 represents white, what is the bit pattern for this image?
29 What is the file size for an image 200 pixels wide, 300 pixels high and with a colour
depth of 4 bits per pixel?
30 A 10 pixel by 10 pixel image has 16 colours. Calculate the size of the image.
100
80
70 X Y
Amount (amplitude) of vibration
60 1 30
50 2 50
40 3 30
30 4 10
20 5 0
10 6 30
0
0 2 4 6 8 10 12 14 16
Time
Figure 3.6 Sound is sampled at set time intervals
Notice that in the example the amplitude of vibration can only be stored to the nearest ten
and the sampling is only done once per second. When the computer uses these values to
recreate the sound we get a shape that is a similar shape to the original but not as smooth and
missing a lot of the detail in the original. In this case the sampled sound will not be an accurate
version of the original sound.
80
70
Amount (amplitude) of vibration
60
50
40
30
20
10
0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Time
Figure 3.7 Digital sound replayed by the computer
101
80
70
Amount (amplitude) of vibration
60
50
40
30
20
10
0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Time
Figure 3.8 Higher sample rates and resolutions produce a better approximation to the original sound
The duration of the sampling is how many seconds of sound are sampled. The more seconds
of sound that are sampled, the more data we need to store and the larger the file needed to
store that data.
The size of the file needed to store sound data depends on these three factors:
● sample rate
● sample resolution
● duration in seconds.
Size of file (in bits) = sample rate × sample resolution × duration in seconds
If there is more than one channel, for example stereo recordings use two channels, we need to
multiply by the number of channels.
102
Worked example
A sample of a sound is made at 44.1 kHz for 1 minute at a resolution of 16 bits. Calculate
the size of the resulting sound file.
44.1 kHz means 44 100 samples per second. Each sample consists of 16 bits. So, the number
of bits per second
= 44 100 × 16
= 705 600 bits per second.
The sample lasts for 60 seconds, so the total number of bits
= 705 600 × 60
= 42 336 000 bits
Divide by 8 to get the number of bytes:
= 42 336 000 / 8
= 5 292 000 bytes
Divide by 1 000 000 for megabytes:
= 5 292 000 / 1 000 000
= 5.29 MB
If this were a stereo recording, we would need to multiply by 2, the number of channels, to
get 10.58 MB.
Knowledge check
31 What is meant by sample resolution?
32 How does the sample rate affect the sound quality and the file size of the file used to
store the sampled sound?
33 Calculate the file size for a 30 second sample at a resolution of 8 bits sampled at 1000 Hz
Lossy
Lossy compression is where some data is removed to make the file smaller.
The removed data is chosen as that least likely to be noticed by the human senses. For
example, certain frequencies of sound are inaudible or barely audible to the human ear, so
these frequencies can be discarded without any significant differences being detected. In
103
images, large areas of similar colour pixels are combined into one block of data so that the
image still looks very similar to the original. For example, within an image we might replace 20
different shades of blue with just ten. Reducing the bit depth in an image will remove the data
and reduce the file size.
Lossless
For some files, losing any information is simply not possible – for example, computer
programs will only work if all the instructions are present. In text files, removing any of the
words or characters would alter the sense of the document. For these files, lossy compression
techniques are not suitable. However, there are techniques for compressing files without losing
any of the original information. This is called lossless compression. This involves storing
enough data and information to be able to recreate the original file exactly as it was before
compression.
104
Character E R Sp H O T
Frequency 1 1 2 3 3 4
Step 3: List the characters as a series of nodes in order of increasing frequency from right to left.
T4 O3 H3 Sp 2 R1 E1
Tech term Step 4: Start to build the tree by replacing the top two nodes with a new node made from
their combined frequencies. Put this into the list in the correct order. Keep track of the original
Branches two nodes by putting them in a new column and linking them with ‘branches’ to the new
The different routes node.
available from a node in In this case, E and R both have a frequency of 1, so they are replaced with a node labelled as 2
a tree structure (i.e. which is 1 + 1).
E1
2
R1
Sp 2
H3
O3
T4
Step 5: We now combine the next top two nodes in the first column to form a new node. As
before, we replace them with a new node that is labelled with their combined frequencies and
then insert that new node in the correct position.
In this case the ‘2’ node is combined with the node for ‘space’ which also has a frequency of 2.
So, the new node has a combined frequency of 4 (i.e. 2 + 2). We need to insert the new node with
the combined frequency of 4 into the table at the correct position. In this case it goes after H
and O both with value 3. Again, we keep track of the nodes that the new ‘4’ node has replaced
by linking them with branches. 105
H3
O3 E1
2
4 R1
Sp 2
T4
Step 6: We continue to combine the two least frequent nodes at the top of the original list
into a single node and then insert it in the correct order.
In this case we combine H and O into a new node, with combined value 6 (i.e. 3 + 3) and insert
this into the list in the correct position – at the end of the list after T, which has the value 4.
E1
2
4
R1
Sp 2
T4
H3
6
O3
Step 7: Again, we combine the top two nodes from the original column – in this case the ‘4’
node and T, to make a new node of frequency 8 (i.e. 4 + 4). 8 is larger than 6 so the new node
goes to the bottom of the list.
H3
6
O3
E1
2
4
R1
8
Sp 2
T4
Step 8: Finally, we combine the final two nodes in the original column, adding their frequencies
together, so that we are left with only one node in the original column. In this case we add the
6 and 8 nodes to make a new 14 node. This completes the diagram.
H3
6
O3
14 E1
2
4
R1
8
Sp 2
T4
You can check that there are no errors by comparing the frequency in the root node (14) with
the total sum of the frequencies in the table.
106
Step 9: We now label the branches starting at the root node, 14. We can label either branch
as 1 or 0, as long as we are consistent. However, it is common to label the upper/right branch
with a 1 and the lower/left branch with a 0. So in this case we label the first branch from 14 to
6 with a 1 and the branch from 14 to 8 with a 0. We continue to label each pair of branches in
this way until they are all labelled with 1 or 0.
1 H3
6
1
0 O3
14 1 E1
1 2
1 4
0 0 R1
8
0 Sp 2
0 T4
The tree can also be drawn with the root at the top and the branches below it.
14
0 1
8 6
0 1 0 1
T4 4 O3 H3
0 1
Sp 2 2
0 1
R1 E1
We can now allocate a code to each letter in the text by following the path from the root node
to the character. For example, E is 0111:
14
0 1
8 6
0 1 0 1
T4 4 O3 H3
0 1
Sp 2 2
0 1
R1 E1
107
Using the Huffman codes, the phrase HOT HOT HOTTER is: 11100001011100001011100000
01110110
The text can be represented by a total of 34 bits (4 + 4 + 6 + 6 + 6 + 8) using this Huffman coding.
In ASCII, each character is represented by a 7-bit binary number. Therefore, the total number of bits
required to code the phrase in ASCII is the total number of characters in the phrase multiplied by 7.
In this case the ASCII code would require:
14 letters × 7 bits = 98 bits.
(If we had created a fixed-length code to represent just these letters, we would have needed
to use 3-bit codes to represent the 6 characters.)
The saving of Huffman coding versus ASCII coding is calculated as:
Saving in bits = number of bits for ASCII coding − number of bits for Huffman coding.
Method ASCII Fixed length Huffman
Number of bits 112 42 34
Saving versus ASCII 0 70 78
coding (in bits)
Using these Huffman codes, we can also represent new phrases made from the same letters,
such as ‘THE TREE’:
0011011101000011001110111
By looking at the codes, we are also able to decode a phrase such as this by comparing the
sequences to the codes generated for the characters.
001101110100110101000
00 11 0111 010 0110 10 10 00
T H E R O O T
The most frequently used symbols are allocated the smallest number of bits. Huffman coding
provides significantly better compression of longer text files than for the short phrase in the
example, and usually significantly better than using a fixed-length code.
108
(Remember that 65 is the ASCII code for A, 66 is the ASCII code for B, etc.) Each of these ASCII
codes takes up 7 bits, and there are six codes, which means the RLE sequence takes up just
7 × 6 = 42 bits.
If we coded the original text directly in ASCII, this would be the sequence:
65 65 65 65 66 66 66 66 66 66 67 67 67 67 67 67 67.
Each ASCII code takes up 7 bits and there are 17 codes, which means coding the original
phrase directly in ASCII would take up 7 × 17 = 119 bits.
RLE only works well when there are large sequences of repeated data. For more random
distributions of characters, the method could easily make the ‘compressed’ file larger than the
original.
RLE can also be used to compress bitmap image files by coding long runs of the same colour
in the same way.
For example, in this black and white bitmap image we have long runs of black pixels and white pixels.
There are 4 black, 16 white, then 12 black. If we use 1 to represent black and 0 to represent
white, we can see there are 4 ‘1’s followed by 16 ‘0’s followed by 12 ‘1’s. We can use RLE to
encode this as: 4 1, 16 0, 12 1
If we wanted to represent this in binary, we can use 1 bit to identify the colour and 7 bits to
identify the number of pixels in that colour. So the first four black pixels can be written as:
10000100, where the first number in bold (1) represents ‘black’ and 0000100 represents ‘4’.
Similarly, the next 16 white pixels are represented by 00010000, and the final 12 black pixels are
represented by 10001100.
So, this image can be represented by three 8-bit numbers:
10000100 00010000 10001100
In contrast, if we simply stored the image in the normal way (as discussed on page 97), then
as there are 32 pixels, the image would require 32 bits or 4 bytes. RLE works well with images if
there are a lot of similar colour pixels in a row.
109
Knowledge check
34 What is file compression?
35 Describe the difference between lossy and lossless compression.
36 Create a Huffman tree for the phrase ‘PIED PIPER’ and calculate the total number of bits
used. How many bits would be used if this were stored as an ASCII file?
37 For this Huffman tree, with the left-hand paths labelled with 1 and the right-hand paths
labelled with 0, identify the codes for S and W.
S E
Sp T L
W H
38 If 1 is black and 0 is white, create the RLE for this sequence of pixels.
39 Draw the sequence of pixels given by this RLE if 1 is black and 0 is white.
2 0, 3 1, 3 0, 4 1
110
128 64 32 16 8 4 2 1
1 0 1 0 0 0 1 0
111
To convert a binary number into a decimal one, add together the column heading values for
every column with a 1 in the binary number.
10100010 is 128 + 32 + 2 = 162 in decimal.
128 64 32 16 8 4 2 1
■ Starting from the left-hand 128 column, find the first column that is smaller than the
decimal number you are converting and write a 1 in that column.
■ Subtract that column heading value from the decimal number to get a remainder.
■ Repeat the process using the remainder, that is, finding the next column value that is smaller
than the remainder.
■ Eventually there will be a remainder of either 1 or 0 to be entered into the right-hand 1
column.
For example, the decimal number 84 is:
128 64 32 16 8 4 2 1
0 1 0 1 0 1 0 0
16 1
112
16 1
A F
113
■ 0 + 1 = 1
■ 1 + 1 = 10 in binary, or 2 in decimal.
Binary shifts
Moving the binary digits to the left or right is called a binary shift.
Moving to the left multiplies the value by 2 for each place the value is shifted.
Moving to the right divides the number by 2 for each place the value is shifted.
128 64 32 16 8 4 2 1
1 1 0 1 0
128 64 32 16 8 4 2 1
1 1 0 1 0 0
Which is 52 (= 26 × 2) in decimal.
114
If we shift the original binary number one place to the right, we get:
128 64 32 16 8 4 2 1
1 1 0 1
It is important that computer systems all agree on these codes and there are some agreed
standards.
ASCII
■ ASCII is an 8-bit binary code able to represent the Roman alphabet, numbers, some symbols
and some control characters.
■ 7 bits are used for characters with 1 bit used as an error check.
■ There are 27 or 128 characters available.
■ Uppercase and lowercase letters have different codes.
■ For example, the letter D is represented by the binary code 1000100 in ASCII, which is the
decimal number 68.
Unicode
■ Unicode originally used a 16-bit binary code to represent many additional non-Roman
characters and a wide range of symbols.
■ The 16-bit code has 216 or 65 536 characters available.
■ Unicode has since been extended to use even more bits to represent billions of characters.
■ The original ASCII codes are the same in Unicode so ASCII can be considered a subset of Unicode.
The binary codes for the main alphabetic characters are allocated to the uppercase characters
in sequence, followed by the lowercase characters in sequence.
For instance, A is 65, B is one more at 66, C is next at 67, and so on. This means that if you are
given the character code for one letter, you can work out the character code for another letter.
Lowercase characters start with a as 97, b as 98, and so on. This means that when we sort
text, Z (which is 90) comes before a.
115
Image size
The image size is expressed as:
width in pixels × height in pixels
Colour depth
With 1 bit for each pixel we have just two possibilities: 0 or 1. This means a pixel can only be one of
two colours.
The following row of pixels is described by the binary code 11100000, where 1 means black and 0
means white:
1 1 1 0 0 0 0 0
To store more than two colours we need more bits per pixel:
■ 2 bits to store 4 (2 ) colours per pixel
2
00 00 11 01 10 11 00 00
Colour depth is the name for the number of bits used per pixel.
116
■ Algorithms look for patterns in the data so that repeated data items only need to be stored
117
Huffman coding
Huffman coding uses a binary tree to represent data, allocating a binary code to each data
element (such as a character).
The most frequently occurring data elements are encoded with the shortest binary codes –
this helps to reduce the overall encoded file size.
The right-hand paths are normally labelled as 1 and the left-hand paths as 0.
The binary code for each character is created by reading the path to the character from the
root of the tree.
For example, in this Huffman tree, O would be encoded as 10, R would be 0110.
0 1
0 1 0 1
T O H
0 1
Sp
0 1
R E
Figure 3.12 Huffman trees are often drawn with the root at the top and branches below
118
For example:
Character E R Sp H O T
Frequency 1 1 2 3 3 4
Huffman code 0111 0110 010 11 10 00
Number of bits 4 4 3 2 2 2
Total (number of 4 4 6 6 6 8
bits × frequency)
The total number of bits for the phrase HOT HOT HOTTER is: 4 + 4 + 6 + 6 + 6 + 8 = 34
If you calculate the number of bits needed for the same phrase in ASCII, you can compare this
to the number of bits needed for Huffman coding. To calculate the number of bits needed for the
phrase in ASCII:
■ Count how many characters there are in the phrase, including spaces.
■ Multiply this number by 7 (because each character in ASCII is represented by a 7-bit code).
Therefore, the number of bits required for the phrase HOT HOT HOTTER in ASCII is: 14 × 7 = 98
Huffman coding this phrase instead of ASCII coding has therefore saved: 98 − 34 = 64 bits.
In this 32-pixel image we have eight black pixels, 17 white pixels and seven black pixels. In binary,
we can store this in three bytes with the most significant bit being 1 or 0 to represent the
colour, the remaining seven bits the number of pixels of that colour.
10001000 00010001 10000111
This uses just three bytes instead of four.
Alternatively we could just represent this as:
8 1, 17 0, 7 0.
119
01.3 How many bits are needed to store a single hexadecimal digit? [1 mark]
01.4 Add together the following three binary numbers, showing your working. [3 marks]
1 1 0 1 1
1 1 0 0 1 0
1 0 0 1 0 1
02.2 Show the result of applying a binary shift of two places to the left. [1 mark]
02.4 What is the effect of applying a binary shift of two places to the left? [1 mark]
03.2 Explain how ASCII represents the character set of a computer. [2 marks]
03.3 Write down the sort order of the following list of words in a program
using ASCII or Unicode to represent the character set: ‘Apple, grape,
cherry, Damson’. [1 mark]
03.4 Describe two differences between using an ASCII character set and a
Unicode character set. [2 marks]
120
A: d B: J C: D D: F E: 4
04 04.1 How does the number of pixels in an image affect the size of the file? [1 mark]
04.2 Describe two differences between an image with a 1-bit colour depth
and an image with a 2-bit colour depth. (Both images have the same
number of pixels.) [2 marks]
04.3 How many colours can be represented using a 4-bit colour depth?
Show your working. [2 marks]
04.4 For the two-colour bit map image below, 0 represents white and
1 represents black. Complete the Run Length Encoding to store
the data for this image. [3 marks]
2 0 2 1 2 0
121
E I P
Sp R
The bit pattern for R is 1101 because it is right, right, left, right to get to R from the root
of the tree.
06.1 Complete the bit patterns for the rest of the characters in the string. [5 marks]
06.2 Calculate how many bits are needed to store the text string using
Huffman codes. [3 marks]
06.3 Calculate how many bits would be required to store the text string using
ASCII codes. [2 marks]
122
123
Key point
When discussing Boolean logic, 1 and 0 are usually used but you may see True and False, T and F
or even On and Off used. We will use 1 and 0, which is also how any questions in your examination
will be presented.
124
Truth tables
A truth table is a table used to display all possible inputs and associated outputs from a logic
system. Inputs are usually labelled with the letters from the beginning of the alphabet and the
output labelled using the letter P or Q.
As an example, consider the situation of learning to drive, where both a practical driving test and a
theory test are needed in order to be given a driving licence. We can assign the input A to ‘passes
the practical test’, input B to ‘passes the theory test’ and output P to ‘can be given a driving licence’.
The table below shows a truth table for this logic system.
Practical test (A) Theory test (B) Driving licence (P)
0 0 0
0 1 0
1 0 0
1 1 1
Note how every possible combination of inputs is listed and the associated output for those
inputs given. We can see that if someone fails both tests, they cannot be given a driving licence.
If they pass one of tests but fail the other, they are still unable to be given a driving licence.
However, if both tests are passed then a driving licence can be given.
Some logic systems have more than two inputs. For example, a logic system with four inputs
would be labelled with inputs A, B, C and D. The more inputs, the more rows are needed in
the truth table; a four-input truth table would have 16 possible permutations of input values.
Truth tables for logic gates using the operators NOT, AND,
OR and XOR
Logic gates are circuits within a computer that produce a Boolean (i.e. 1 or 0) output when
given Boolean inputs. There are four logic gates that we need to know about for GCSE: NOT,
AND, OR and XOR.
NOT gate
The NOT gate is sometimes known as an inverter. It only has one input and it outputs
the opposite of the value input. If a 0 is supplied as an input then a 1 will be produced as the
output. Conversely, if a 0 is supplied as the input then a 1 will be the output. This is shown in
the truth table below:
Tech term A P
0 1
Inverter
1 0
An alternative name for
a NOT gate, because the The symbol used to denote a NOT gate is shown in Figure 4.2.
output inverts the input.
Input Output
A P
AND gate
An AND gate has two inputs and only produces a 1 as output if both of the inputs are 1s. If
any other combination of inputs is given then the output will be 0.
A B P
0 0 0
0 1 0
1 0 0
1 1 1
Inputs
A
Output
P
B
The Boolean expression above is written as P = A AND B. The · symbol is used to represent an
AND gate, so this expression can also be written as P = A . B.
OR gate
An OR gate has two inputs and produces a 1 as output if either or both of the inputs are
1s. If both inputs are 0 then the output will be 0.
A B P
0 0 0
0 1 1
1 0 1
1 1 1
Inputs
A
Output
P
B
The Boolean expression above is written as P = A OR B. The + symbol can be used to represent
an OR gate, so this expression can also be written as P = A + B.
126
XOR gate
An XOR gate, or Exclusive OR gate, has two inputs and produces a 1 as output only if one of
the inputs is a 1. If both inputs are 0, or both inputs are 1, then the output will be 0.
A B P
0 0 0
0 1 1
1 0 1
1 1 0
The Boolean expression above is written as P = A XOR B. The symbol ⊕ is used to represent
an XOR gate, so this expression can also be written as P = A ⊕ B.
An easy way to remember the purpose of these logic gates is to think about what inputs
produce a 1 output.
● NOT requires the input NOT to be 1.
The output for this can be worked out in stages. It is useful to think about the output of each
gate in turn and we can even add this to our truth table. Here, R is the output from the first
part of the logic diagram and P is the final output.
A B R = (A AND B) P = (NOT R)
0 0 0 1
0 1 0 1
1 0 0 1
1 1 1 0
B
R
Output
P
C
The truth table now requires more rows to cater for all of the possible input values.
The first thing you need to do is fill in all of the different permutations of the inputs A, B and C.
A B C R = (A AND B) P = (R OR C)
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
Then you need to fill in the values for R for all permutations of A and B.
A B C R = (A AND B) P = (R OR C)
0 0 0 0
0 0 1 0
0 1 0 0
0 1 1 0
1 0 0 0
1 0 1 0
1 1 0 1
1 1 1 1
Once the R column is completed you can then fill in the values for P for all the permutations
of R and C.
A B C R = (A AND B) P = (R OR C)
0 0 0 0 0
0 0 1 0 1
0 1 0 0 0
0 1 1 0 1
1 0 0 0 0
1 0 1 0 1
1 1 0 1 1
1 1 1 1 1
128
Key point
To make sure that you don’t miss out any permutations of input values, try counting up in binary,
starting at 000 (if you have three inputs), then 001, 010, 011, and so on.
Another check is that with n inputs, there should always be 2n rows in the truth table (not counting
the heading). This means that for 3 inputs, we need 23 = 2 × 2 × 2 = 8 rows.
Input
A
B R
Output
C P
This truth table again requires more rows to cater for all of the possible input values.
The first thing to do is fill in all of the different permutations of the inputs A, B and C.
A B C R = (A XOR B) P = (R AND C)
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
Then you need to fill in the values for R for all permutations of A and B.
A B C R = (A XOR B) P = (R AND C)
0 0 0 0
0 0 1 0
0 1 0 1
0 1 1 1
1 0 0 1
1 0 1 1
1 1 0 0
1 1 1 0
129
Once the R column is completed you can then fill in the values for P for all the permutations
of R and C.
A B C R = (A XOR B) P = (R AND C)
0 0 0 0 0
0 0 1 0 0
0 1 0 1 0
0 1 1 1 1
1 0 0 1 0
1 0 1 1 1
1 1 0 0 0
1 1 1 0 0
Knowledge check
Create truth tables for the following expressions:
1 P = C AND (A OR B)
Input
A
B P
C
2 P = A OR (NOT B)
A
P
3 P = NOT (A OR B)
A
P
B
P
B
C
A
P
B
C
130
P
C
B
Worked example
Take the example P = NOT (A AND B) AND C.
As with mathematics, use of brackets help us decide what has priority. In this case, A AND B
is an expression in brackets and therefore should be looked at first. The logic diagram for
this is:
Inputs
Output
A
R
Next, the NOT gate should be applied to this expression to give us NOT (A AND B). The
logic diagram for this is:
Inputs
A
Output
P
B
Note that the NOT gate is applied to the output of the expression A AND B, not on either
of the inputs.
131
Finally, the expression is complete by joining the output of NOT (A AND B) in the previous
stage to AND C. This gives us NOT (A AND B) AND C as shown in this logic diagram:
A
B P
C
Knowledge check
Create logic diagrams for the following expressions:
7 P = A OR (NOT B)
8 P = A OR (B OR C)
9 P = A AND (NOT B)
10 P = (A OR B) OR (C OR D)
Worked example
In the example below we can see that there is an OR gate and an AND gate:
Input
A
B P
C
We need to work through the circuit logically, working through the inputs in turn and then
following these through to the output. Here, A OR B is fed through to the AND gate so we
can use brackets to show that this needs to be done first:
P = (A OR B) AND C
132
Worked example
In the following example there is an OR gate and a NOT gate.
A
P
Here, input A is fed directly into an OR gate. However, input B passes through a NOT gate
before feeding into the OR gate. Therefore, we describe this as P = A OR (NOT B).
Knowledge check
Create Boolean expressions for the following logic circuits:
11
A
P
B
12
133
This then allows us to apply these logical rules to check if certain holidays are
appropriate.
Systems software
Systems software controls the hardware inside the computer and provides an interface
for users to interact with it. It is comprised of the operating system and utility software.
Utility software
Utility software is a collection of programs, each of which does a specific housekeeping
task to help maintain a computer system. Most computers have utility software installed
alongside the operating system.
Utility software is not essential for the computer to work, but it helps to configure the system,
analyse its performance and make changes to ensure that it is running efficiently.
Types of utility software include:
● encryption
● defragmentation
● data compression
● backup.
Encryption software
Encryption is the scrambling of data into a form that cannot be understood if it is accessed
by unauthorised users. It is used to protect data from unauthorised access. The encryption
process uses an algorithm and a key to transform the plaintext into ciphertext. The same
algorithm and key are needed to decode the information.
Tech term Modern operating systems have built-in encryption utilities that enable the user to encrypt
Ciphertext specific files or entire drives – for example BitLocker on Windows and File Vault on macOS.
Encrypted text. Files on systems like these are automatically decrypted when they are accessed by an
authorised user.
134
Defragmentation
When data is stored on a magnetic hard disk drive it is saved to different areas of the disk
depending on where there is space available. If the data file is larger than the free space available
in one part of the disk, it is split into separate blocks of data that are saved in different places.
This is called fragmentation.
Over time, the contents of a hard disk drive become increasingly fragmented and it begins
to affect performance. This is because hard disk drives are mechanical devices and the read/
write head has to move to the correct physical location on a disk to read its contents (see
section 4.5). When the data is fragmented, the disk needs to be accessed more frequently
to read all of the data.
Defragmentation is the process of organising and moving the separate parts of the data files
so that they can be stored together in one location on the hard disk drive. Since the heads do
not have to travel between areas of the drive to access data, it makes the data faster to access.
Defragmentation also groups all of the free disk space together so that new files can be stored
in one place. This improves the performance of the computer.
Fragmented data
Defragmented data
Backup
Data stored in secondary storage is potentially at risk from loss or damage and important data
should be backed up. Special software on the system is able to perform backup operations.
135
Knowledge check
13 Define what is meant by utility software.
14 Give three examples of utility software.
15 Explain why encryption software is used.
16 State one problem caused by a fragmented disk.
17 Identify two situations where compression software might be used.
Application software
Application software is the end-user programs that are designed to perform specific tasks,
such as word processing, spreadsheets, photo editing, and so on, or used for entertainment
such as playing games or watching videos. There are also many programs written for specific
applications, such as company payroll systems, pupil management systems, air traffic control
and traffic control.
Operating systems
Operating systems are found in almost all computing devices, from video game consoles
to mobile phones, tablets to desktops, and data servers to supercomputers. They control the
general operation of the system or device and provide a way for users to interact and run
programs.
Well-known operating systems include:
● Windows
● macOS
● Linux
● Ubuntu
● Android
● iOS.
The operating system (OS) manages the hardware in a computer and provides an environment
for applications to run. It is essential to the function of any computer.
The functions controlled by the OS include the management of:
● processor(s)
● memory
● applications
● security.
Processor management
Modern operating systems, such as Windows and macOS, allow several programs to be run
Tech term simultaneously – this is known as multitasking. For example, a user may be working on a
word-processed document, while listening to music that is being streamed via the internet.
Multitasking
Processor management involves the allocation of processor time to each task that needs
This is when a computer
to be carried out by the different programs and processes running on a computer at any
performs more than one
one time. Processor time is shared between applications so that they appear to be running
task at the same time.
simultaneously.
136
If a computer has a multi-core processor then the operating system will allocate tasks to each
core wherever possible.
Memory management
The memory manager controls the use of RAM by allocating blocks of free space in the main
memory to each program as it starts up. Memory is typically broken up into fixed-size blocks,
called pages. The operating system works out how much memory a program is likely to require
and allocates sufficient pages to hold the program and its files. When a program is closed, the
allocated pages are freed up so that they can be used by another program.
The memory management system keeps a record of where the data for each program is
being held so that it can be fetched when it is needed.
Knowledge check
18 State two functions of an operating system.
19 Explain how an operating system manages memory in a computer system.
20 Explain what is meant by device drivers.
21 Explain how an operating system manages the processor of a computer system.
22 Identify two ways in which the operating system helps to keep the system secure.
137
10110101 10010010
01101101 10110001
00100111 11100101
01101101 10110001
Figure 4.10 A simple program written in machine code
In fact, early computers were programmed in this way. Binary 1s and 0s could be input into the
computer by physically moving switches or connecting wires, as with ENIAC, the Electronic
Numerical Integrator And Computer, which was first used in 1945.
Figure 4.11 The early computer ENIAC (Electronic Numerical Integrator And Computer)
138
Other computers allowed programs to be input using punched paper, tape or cards to
represent the binary 1s and 0s. Entering instructions in binary was obviously very time-
consuming and mistakes were hard to spot. Every different type of computer also had its own
version of machine code and so programs written on one computer would not necessarily run
on another computer.
Low-level languages
Machine code is a low-level language. This means that it can be run directly by the
Tech terms processor with no translation needed. It also has little or no abstraction; each instruction
Abstraction deals directly with the computer’s hardware and so a machine code programmer would need
Removing unnecessary to understand the inner workings and hardware structure of the processor. Something as
detail. The programmer simple as adding two numbers up would take numerous steps to load data into registers,
of a high-level language perform the addition and then store the answer in memory. The programmer would need to
does not need to know specify each of these steps.
exactly how a processor Low-level programs are also hardware-dependent – they will not run on a different type of
performs a particular computer or processor as the machine code instruction-set for that computer or processor is
task. High-level language likely to be different.
instructions are an One simple way to make low-level programming slightly easier is to replace the binary machine
abstract representation code instructions with short mnemonics (for example, replacing a binary instruction such as
of what is actually 00100111 with ADD). This is known as assembly language. It requires a program called
happening in the an assembler to convert the mnemonics back into their binary equivalents before the
processor itself. processor can execute them. While assembly language is easier to use than machine code,
Mnemonics it is another example of a low-level language. Because each assembly language mnemonic
In assembly language, a represents one machine code instruction, machine code and assembly language have a one-
text code that represents to-one (1:1) correspondence.
a machine code The ‘Little Man Computer’ is an excellent introduction to programming using assembly
operation. language. You can find an LMC simulator on a number of websites – simply search for ‘little
man computer’.
One advantage of a low-level language is the sheer speed of program execution. Using
machine code allows a programmer to make their program run as fast as possible with no
unnecessary routines. Programmers can also be very efficient in their use of primary and
secondary storage.
Low-level languages such as machine code were once the only way to program a computer.
Nowadays, assembly language is often used to develop software for embedded systems (where
speed on relatively low-powered hardware is important) or for controlling specific hardware
components such as device drivers.
High-level languages
Languages like Python, C# and Visual Basic are examples of high-level languages. There
are many different high-level languages, each with its own specific use. For example, PHP and
JavaScript are used to create web applications, whereas Visual Basic is commonly used to
create desktop applications for Windows computers.
Key point
Java and JavaScript are two very different languages. They may share the same first part of their
name, but then again so do ham and hamster or car and carpet.
139
By hiding this underlying detail, programming becomes much easier. It also means that high-
level languages are hardware-independent – which means they can run on many different
types of computer.
However, programs written in high-level languages cannot be executed directly by the
processor in a computer. They must first be translated into machine code, a process that takes
time to carry out.
Low-level language High-level language
Advantages Can be run directly by the CPU Once programs have been translated,
they can be run on different hardware
Very fast to execute Easy to read and write code as the
language is very similar to English
Allows the programmer to focus on
what needs to be done rather than
how the computer works
Disadvantages Hardware dependent so will only run Needs to be translated to be run by
on the specific hardware it is has been the CPU
developed for
More difficult to read and write code Each language has its own specific
as it is not like English syntax and keywords
Slower to execute as needs to be
translated
Key point
High and low in this context refers to the level of abstraction away from the processor. Low-level
languages are so-called because they are very closely related to how the processor works. High-level
languages are much further away.
140
Knowledge check
23 Name three high-level languages.
24 Give two advantages that high-level languages have over low-level languages.
25 Give one advantage that low-level languages have over high-level languages.
Program translators
A translator is a piece of software that converts high-level code into low-level machine code
that can then be executed by the processor. Without translators, high-level programming
languages like Python would not exist.
141
compilation process has completed, an executable file is produced that the processor can
run directly. The executable file can be saved and run in the future without needing to
compile it again.
Most applications that a user would buy or download will have been compiled; the executable
file is distributed so that users can run it. This also has the advantage of not allowing users to
view or modify the high-level program code.
In contrast, an interpreter translates one line of high-level code and then immediately runs
this before moving on to translate and run the next line of code. Interpreters call appropriate
machine code subroutines within their own code to carry out commands. No executable
file is produced and when the program is run again in the future, the interpreter must
retranslate every line of code again. If code that is run using an interpreter is distributed, all
of the source code for the program must be shared. Therefore, interpreters are generally
used when developing programs, or when a program needs to be run on different types of
hardware.
Another important difference between compilers and interpreters is the speed of execution
of programs. Because compilers translate everything first, the program itself runs quickly.
Conversely, because interpreters only translate one line at a time, this translation is happening
while the program is running, which slows it down.
An assembler is needed to convert assembly language into machine code. Assembly language
has a 1:1 correspondence with machine code. This means that each instruction in assembly
language translates into one instruction in machine code.
Compiler Interpreter Assembler
What does Translates every line of a Translates one line of Translates low-level
it do? high-level program into high-level code and then assembly language into
machine code to produce executes it immediately machine code
an executable file
When is it Used to create an Used when developing Is used to produce an
appropriate executable file that can programs as it makes it executable file from
to use? be run at any time. As the easy to spot where errors assembly language that
source code is not shared, have occurred. This is can be run at any time
the program cannot because the program
be modified easily. will stop running and will
This makes it ideal for give an error message
distributing commercial indicating what the
software problem is
Key point
Compilers, interpreters and assemblers are all hardware-dependent. Different processors or
computers require different translators, even if the high-level language that is being translated is the
same.
142
Figure 4.14 Python interpreter available for PC (Windows, Linux) and Mac (OS X)
Knowledge check
26 Give two ways that code can be translated from high-level code into machine code.
27 State the role of an assembler.
Storage
Figure 4.15 Input–process–output. Processing and storage is the job of the CPU
if it represents the value 9. The CPU relies on the logic of the program to decide what to do. If
it expects an instruction it will try to decode it and carry it out; if it expects a value it will treat
it as a number.
Von Neumann architecture is the fundamental design concept behind all modern computer
systems.
● Logical operations and comparisons such as AND, OR and NOT, and the result of less than,
greater than, equal to comparisons.
● Binary shift operations (moving the binary digits in a binary value left or right).
The ALU carries out the calculations and logical decisions required by the program instructions
that the CPU is processing.
Control unit (CU): The control unit’s purpose is to coordinate the activity of the CPU.
It does this by:
● obtaining then decoding instructions from memory
● sending out signals to control how data moves around the parts of the CPU and memory
to execute these instructions.
Clock: A vibrating crystal that generates digital pulses at a constant speed. Typical modern
computers work at speeds of up to 4 GHz (or 4 billion instructions per second). The clock
synchronises all the CPU activity.
144
Registers: Memory locations within the CPU that hold data temporarily and can be accessed
very quickly. Their role in the CPU is to accept, store and transfer data and instructions for
immediate use by the CPU.
Buses: Communication channels through which data moves. They enable data and control
signals to move around the CPU and main memory.
Memory
CPU
Address bus
Control bus
Data bus
Registers
Control
ALU Input/Output
unit
145
copied from main memory. If they are not in the cache memory then the CPU will locate
them in the main memory, copy the data or instructions to cache and then to the CPU.
Main
If data not in cache: memory
request data from
main memory
The more data that can be stored in the cache rather than main memory, the faster and more
efficient the process. Data that is likely to be required will be transferred to cache, ready to be
used. The more cache memory, the more likely it is that the required data will already have
been copied across and will not need to be fetched from main memory. Cache memory is very
expensive and while a mid-range laptop may have 8 GB of RAM (main memory) it is likely to
have just a few MB of cache.
Knowledge check
28 What is a meant by a quad core processor?
29 What is meant by 2.3 GHz when describing a CPU?
30 Describe how cache memory is used by the CPU.
31 Describe three characteristics of a CPU that affect its performance.
146
Fetch
Execute Decode
Knowledge check
32 Describe the purpose of the CPU in a computer.
33 Describe the Fetch–Execute cycle.
34 What is the purpose of the registers in the CPU?
35 State two arithmetic and two logical operations carried out by the Arithmetic Logic
Unit (ALU).
Memory
A computer system needs to have memory for any data that it needs to access quickly. This
includes the start-up instructions, the operating system, programs that are running and any
associated data.
The memory in a computer is made up of main memory, cache memory and registers. Cache
memory and registers have already been discussed. They are small but have the fastest access times.
147
Main memory is directly accessible by the CPU. There are two main types of main memory:
RAM and ROM.
RAM is volatile, meaning it needs electrical power to operate. Any data stored in RAM is lost
when the power is turned off.
RAM is read/write, which means it can be read from or written to by the computer.
148
Knowledge check
36 State two differences between RAM and ROM.
37 What is held in RAM while the computer is working?
38 What is held in ROM on the computer?
Secondary storage
The need for secondary storage
Computer systems would be of little value if we lost all of our data and programs every time we
switched them off. We need to store the operating system, data, images, programs, documents
and various other files so that they are available the next time we switch on the computer. This
kind of data requires a lot of space so we need a low-cost, high-capacity, non-volatile storage
medium. This is known as secondary storage. Secondary storage needs to keep this data
safe and must be robust and reliable.
The main difference between main memory and secondary storage is that primary storage is
directly accessible by the CPU, whereas secondary storage is not.
Knowledge check
39 Why do we need secondary storage?
40 What is stored on secondary storage in a computer system?
Magnetic storage
Magnetic storage uses the principle of magnetism to store data. Hard disk drives
(HDDs) are magnetic and are the most common type of secondary storage. They are made
of a stack of rigid disks (called platters) on a single spindle that rotates. Each platter is coated in
a magnetic material that is effectively made up of billions of separate tiny magnets, which can
either point ‘north’ or ‘south’. Each bit of data is represented by these tiny magnets – north for
‘1’ and south for ‘0’. A set of ‘heads’ move across the platters, reading or writing data by sensing
or changing the north/south alignment of the magnets.
Figure 4.21 A hard disk drive showing the platters and heads
149
The magnetic hard disk is a reliable and cost-effective storage solution, providing high capacity
at low cost. This makes it an ideal choice for large amounts of storage. Internal and external hard
disk drive capacities are currently measured in terabytes (a million megabytes – see section
3.3). Large hard disk drives are, however, less portable than solid-state drives or optical disks
and are subject to damage if dropped or brought near to strong electric or magnetic fields.
Several drives can be combined in larger commercial systems to provide a significant amount
of storage at a reasonable cost. At the other end of the scale, there are small portable hard disk
drives that can easily be moved between computers.
Solid-state storage
Solid-state storage uses a technology called flash memory that uses electronic circuits
to store data. It has very fast data access times, largely because there are no moving parts.
Solid-state storage is, however, relatively expensive compared to hard disk drives and typically
has a lower capacity.
Solid-state storage is widely used for portable devices such as cameras (e.g. memory cards)
and comes in a range of physical sizes and capacities to suit a wide range of applications. It is
frequently used to back up or transfer data between devices (e.g. USB pen drives).
Tech terms Solid-state flash memory is used as the basis for solid-state drives (SSDs). SSDs have begun
to replace magnetic hard disk drives (HDDs) because they have many advantages over them:
Flash memory
● In order to read data, magnetic HDDs have to line up the correct portion of the disk with
Memory made from
the position of the read/write head. This means the magnetic disk platter has to rotate to
electrical circuits.
the correct position and the head has to move across the platter. This in turn means there
Latency is a delay before data can be read or written. This delay is called latency. SSDs have lower
A delay before data can latency times because there are no moving parts and access to the data does not require a
be transferred. platter to rotate or the read/write head to move. This improves access to the data and the
Fragmentation performance of the device.
Data saved in different ● The lack of moving parts means that SSDs have much lower power requirements and do
physical locations across not generate any heat or noise.
a magnetic hard disk
● HDDs can suffer from data being fragmented over the surfaces of the platters, producing
drive.
very slow access speeds. This is not the case with SSDs.
150
● SSDs are significantly lighter, smaller and thinner than HDDs making them particularly
suitable for small, thin portable devices such as tablet computers or other portable devices.
● Since there are no moving parts, SSDs are not susceptible to problems caused by sudden
movements, making them ideal in hostile environments or in portable devices.
Given the expense of SSDs, they are often combined with a magnetic disk drive to form a
hybrid system. Frequently accessed data, such as the operating system, is stored on the SSD,
while larger, less frequently required data files are stored on the magnetic disk. This provides
the speed advantage of the SSD with the capacity advantage of the HDD at a reasonable cost
compared to high-capacity SSDs.
Optical storage
Data can also be stored by using the properties of light. Typical optical storage media
include CDs, DVDs and Blu-Ray disks. These are optical devices because they are written to and
read from using laser light. The surface of each disk is covered in billions of small indentations.
When light is shone onto the surface, it is reflected differently depending on whether or not it
strikes an area with an indentation. The difference in reflections is detected and interpreted as
a ‘1’ or ‘0’, to represent a bit of data.
Some optical storage media are read-only but others can be written to by creating pits on the
surface of the disk using laser light.
Typically, a CD will hold around 700 MB of data and costs pennies. CDs are used to distribute
data and programs or make semi-permanent copies of data.
The DVD is very similar to the CD but has a larger capacity of 4.7–8.5 GB. This means that a
DVD can store more data than a CD, such as standard resolution movies. A DVD has a faster
access time than a CD and costs a little more, but is still only pennies.
Blu-Ray is similar but with significantly larger capacity (25–50 GB) and access speeds. Blu-Ray
disks can be used to store large amounts of data and the much higher access speed makes
them particularly suitable for high-resolution movies and console games. They are slightly
more expensive than DVDs but still reasonably inexpensive.
Type CD DVD Blu-Ray
Typical cost 18p 60p–80p £1.80–£3.00
Capacity 700 MB 4.7 GB single layer 25 GB single layer
8.5 GB dual layer 50 GB dual layer
151
The table below summarises the advantages and disadvantages of the three types of storage.
Advantages Disadvantages
Magnetic ● Large capacity ● Slower access speeds than solid-
storage ● Small drives can be portable (but state
this increases risk of damage) ● Large hard drives are not portable
● Reliable for medium term storage ● Not as durable – shocks and
of 5–7 years strong electric/magnetic fields can
● Low cost per GB easily damage a hard drive
Solid-state ● Very fast access speed ● Lower capacity than magnetic
storage ● Very portable storage (though larger than optical
● Very durable storage)
● Likely to be reliable over a very ● More expensive per GB than
long period of time magnetic drives
Optical ● Very portable ● Limited capacity
storage ● Very durable – can withstand ● Slowest access times
shocks and extreme conditions ● Cost per GB is expensive on CDs
(but not scratches)
● Reliable for many, many years if
looked after
● Cost of individual disks is small
Cloud storage
The cloud is a generic term that refers to storage, services and applications that are accessed
via the internet rather than being stored locally on your computer, tablet or phone.
The cloud is effectively a network of servers, some that store data and others that run applications.
These servers use magnetic or solid-state storage and are housed in giant data centres around the
world. Users do not actually need to know the geographical location where their data is stored.
Examples of cloud storage services and applications include:
● file storage and sharing, e.g. Google Drive, DropBox, iCloud Drive, One Drive
152
Knowledge check
41 State what is meant by cloud computing.
42 Identify two services that can be accessed via the internet.
43 Explain two disadvantages of storing your data in the cloud.
Embedded systems
An embedded system is a computer system that has a dedicated function as part of a
larger device. The main components of a computer are either manufactured onto a single chip
(a microcontroller) or separate circuits for processing and memory are combined into a larger device.
When a computer device is required to perform a single or fixed range of tasks it can be
engineered to reduce its size and complexity in order to focus only on these tasks. Dedicated
software will be programmed into the device to complete the necessary tasks and nothing
else. The reduction of complexity of the hardware and the dedicated nature of the software
will make the device more reliable and cost effective than using a general-purpose computer.
The embedded system will typically include some ROM to store the dedicated program and
some RAM to store user inputs and processor outputs. For example, in a washing machine,
the ROM will store all of the data describing the separate washing cycles; the RAM will store
the user’s selected options (inputs) and the data used to display choices and progress of the
washing cycle (outputs).
Embedded systems have the following characteristics:
● Low power so they can operate effectively from a small power source such as in a mobile
phone.
● Small in size so they can fit into portable devices such as a personal fitness device.
● Rugged so that they can operate in harsh environments such as car engine management
systems or in military applications.
● Low cost, making them suitable for use in mass-produced, low-cost devices such as
microwave ovens.
● Dedicated software to complete a single task or limited range of tasks, such as in
computer aided manufacture or control systems.
153
Embedded systems contain many of the same components as non-embedded systems, but
differ in two aspects:
● The software in an embedded system will be custom-written for the task and will not be
typical general-purpose software found in non-embedded computer systems.
● The software in an embedded system will be written to non-volatile memory rather than
being loaded into RAM, as in non-embedded computer systems.
● telephones
● televisions
Embedded systems are also widely used within larger and more complex systems such as:
● car engine management
● airplane avionics
● computer-controlled manufacturing
These systems are frequently connected to the internet via Wi-Fi to exchange data with third
parties, for example water meters, energy smart meters, home security and heating monitoring
systems.
Embedded systems are particularly useful for those with physical disabilities as they can make
items more accessible. This includes voice control for gadgets in the home and systems that
adapt motorised vehicles so they can be operated using limited physical movements.
Knowledge check
44 Explain why embedded systems have both RAM and ROM.
45 Identify one input and one output from the embedded system in a microwave oven.
46 Give two examples of systems that use embedded computer systems and explain why
it is the most appropriate type of computer system to use in each case.
155
156
Inputs
A
Important words Output
P
B
hard disk drive (HDD)
magnetic storage
solid-state storage
The Boolean expression for the AND gate can be written as
solid-state drive (SSD)
optical storage P = A AND B or P = A ∙ B
cloud storage OR gate
embedded system
A B P
0 0 0
0 1 1
1 0 1
1 1 1
Inputs
A
Output
P
B
A
Output
P
B
The Boolean expression for the XOR gate can be written as:
P = A XOR B or P = A ⊕ B
157
A
B P
C
Application software is the end-user programs that are designed to perform specific tasks,
such as word processing, spreadsheets, gaming, video editing, and so on.
The operating system (OS) controls the general operation of the computer system or device
and provides a way for users to interact and run programs.
The OS controls things such as:
■ processor(s)
■ memory
158
■ security.
Program translators
A translator is a piece of software that converts high-level code into low-level machine code.
There are three common types of translator: compilers, interpreters and assemblers.
A compiler works through the high-level code, translating every line into machine code, and
produces an executable file that is specific to the hardware.
159
■ The original high-level code is not shared with the end user.
■ Once a program has been compiled, the executable file executes quickly and does not need
■ Each time a program is executed it must be re-interpreted. This slows down the speed of
execution.
An assembler is needed to convert assembly language into machine code. Assembly language
has a 1:1 correspondence with machine code – one instruction in assembly language translates
into one instruction in machine code.
Nearly all modern computer systems are based on Von Neumann architecture.
160
■ Registers: Memory locations within the CPU that hold data. A register may hold an instruction,
a storage address, or any kind of data. The data in registers can be accessed very quickly.
■ Buses: Communication channels through which data moves. Buses connect the CPU with main
memory and any input/output devices.
■ Clock chips currently operate at speeds of up to 4 GHz or 4 billion instructions per second.
Cache memory
■ Cache memory is small in size but can be accessed very quickly by the CPU.
■ Having more cache will provide the CPU with faster access to data.
Memory
A computer needs memory for data it needs to access quickly. This includes:
■ start-up or boot instructions
■ the operating system
■ programs that are running
■ any data associated with the operating system or programs.
Memory in a computer is made of main memory, cache memory and registers.
■ Registers are tiny memory locations within the CPU with very fast access times.
■ Cache memory sits between the processor and main memory (RAM). It is very small in size but
161
RAM
Random access memory (RAM) is volatile, which means it needs constant power to maintain it.
If the power is turned off, the RAM loses its contents.
■ RAM holds the operating system, and any applications and data currently in use by the
computer.
■ The CPU can access RAM quickly – much faster than it can access secondary storage such
as a hard disk drive.
■ The more RAM in a computer, the more programs and data it can run at the same time and
the better the computer’s performance.
■ RAM is read/write, which means it can be read or written to.
ROM
Read-only memory (ROM) is non-volatile, which means it does not need power to maintain it.
If the power is turned off, ROM keeps its contents.
■ ROM provides storage for data and instructions needed to start up the computer (also
known as the boot process).
■ ROM content is read-only, which means it cannot be overwritten. Information in ROM
is normally written at the manufacturing stage.
RAM ROM
Is volatile and needs power to maintain the Is non-volatile and does not require power to
content maintain the content
Is read and write – data can be read from Is read-only – the computer cannot overwrite
and written to RAM by the computer ROM
Holds the operating system and any programs Holds the data and instructions required to
and data currently in use by the computer start up (boot) the computer
Secondary storage
Secondary storage is needed to permanently store files and programs. It needs to be:
■ non-volatile – i.e. it doesn’t lose data when switched off
■ low cost
■ high capacity
■ reliable.
Magnetic storage
Magnetic hard disk drives (HDDs) are the most common type of magnetic secondary storage.
■ They use a stack of magnetic platters (or disks) that rotate.
■ A moving read/write head moves across the surface of the platters to read and write data.
■ Magnetic disks are reliable and cost effective and provide high-capacity storage at low cost.
162
Solid-state storage
Solid-state storage uses electronic circuits to store data. Solid-state storage is used in
portable hand-held devices and increasingly in computers in the form of solid-state drives (SSDs).
■ SSDs use flash memory and have no moving parts.
■ No moving parts means access to data is faster than for a magnetic hard disk drive.
■ No moving parts also means power requirements are low and no noise or heat is generated.
■ SSDs are robust, lightweight and compact, making them ideal for use in portable devices.
■ SSDs have a smaller storage capacity than magnetic hard disk drives and the cost per unit
of storage is higher.
■ SSDs are commonly used in tablet computers, mobile phones, cameras and general-purpose
computers.
Optical storage
Optical devices use the properties of light to store data.
■ The most common optical storage medium are optical disks – CDs, DVDs and Blu-Ray disks.
■ They work by reflecting laser light onto the surface of the rotating disk and reading the
reflections as 1s or 0s.
■ Blu-Ray disks have a much higher capacity than CDs and DVDs, making them ideal for storing
and distributing high definition video films or large amounts of data.
■ Optical media are low cost and robust, making them an ideal way to distribute data.
163
Advantages Disadvantages
Optical storage ● Very portable ● Limited capacity
● Very durable – can withstand ● Slowest access times
shocks and extreme condi- ● Cost per GB is expensive on
tions (but not scratches) CDs
● Reliable for many, many years
if looked after
● Cost of individual disks is
small
Cloud storage
■ The cloud is a generic term that refers to services and applications that are stored or
run on remote servers accessed via the internet rather than being stored locally on your
computer, tablet or phone.
■ These remote servers use magnetic or solid-state storage technology.
Embedded systems
■ An embedded system is a computer system that has been designed for a dedicated function
as part of a bigger system. Embedded systems are often manufactured as a single chip.
■ The dedicated hardware and software make embedded systems more robust and reliable than
general-purpose computers.
164
performance.
■ Programs are often uploaded at the manufacturing stage, directly to the device.
165
C G2
E
01.3 Complete the following truth table for the logic circuit shown in the figure
above by filling in the missing cells. [3 marks]
A B C D E P
0 0 0 0 1 1
0 0 1 0 0 0
0 1 0 0 1 1
0 1 1 0 0 0
1 0 0
1 0 1 0 0 0
1 1 0
1 1 1
01.4 Give the Boolean expression for the logic diagram shown in the figure. [1 mark]
03.2 Explain why the computer needs to translate the program code before
it is executed. [1 mark]
166
04 04.1 E xplain why a developer would normally use a low-level language when
writing programs for an embedded system. [2 marks]
04.2 Describe two differences between high-level and low-level languages. [4 marks]
05.2 How does the number of cores affect the performance of the computer? [2 marks]
05.3 Explain one reason why cache size can affect the performance of the
computer. [2 marks]
(ii) State two examples of processes carried out by the ALU. [2 marks]
167
08.3 Describe two inputs and one user interface output for such a system. [6 marks]
Embedded systems are also used in heart monitors and pacemakers implanted
inside people's chests to monitor and control their heart rate.
08.4 Identify and describe two features that make an embedded system
appropriate for use in a heart monitor or pacemaker. [6 marks]
168
Another advantage of computer networks is the ability to exchange data between computers
without needing to use physical media such as memory sticks or external hard drives. This can
be particularly useful in a school or office setting and can be achieved using shared drives and
folders. This also allows files to be backed up centrally.
Using networks in larger organisations like schools and businesses allows computers to be
managed centrally by a network manager. This enables them to update software remotely and
manage security centrally through the use of firewalls and anti-malware software. They can
also control access to files and resources for different users, and user activity can be monitored.
Users are able to log in to any computer on the network and still access all of the same
resources. This means that files can be accessed from wherever they are needed, and separate
computers are not needed for every single user.
170
Workstation Workstation
Server
Network
LAN
WAN users
switch
LAN LAN
171
Knowledge check
1 State two advantages of using a computer network.
2 State two disadvantages of using a computer network.
3 Describe the characteristics of a LAN.
4 Give one example of a type of technology used in a PAN.
5 Identify two differences between a LAN and a WAN.
Wired networks
Wired networks use either copper network cables or fibre-optic cables to physically
connect the devices. They are often found in office networks where the devices tend to be in
fixed places and do not move around.
Copper cable
Tech terms
Inside copper cables there are individual copper wires, which are arranged in pairs. Each
Bandwidth pair of cables is twisted together to reduce interference from other signals and therefore
How much data can be improve transmission.
transmitted, normally Data is transmitted using electrical impulses. There are different ratings that indicate how
measured in bits per quickly the cable can reliably transmit data and over what range. The bandwidth is generally
second. between 100 megabits per second (Mbps) and 1 gigabit per second (Gbps), for a distance of
Ethernet port up to about 100 metres.
A special socket on a Most PCs have built-in ethernet ports, so connecting computers using copper cable can
computer that allows be a cost-effective option if the bandwidth is adequate. Copper cable is also already found
it to be connected to a in telephone networks, and using this existing infrastructure saves the cost of installing new
wired network using the cables specifically for computer networks.
ethernet protocol (see Copper cable is relatively cheap to install within a small geographic area, such as a LAN within
page 176). an office building.
Fibre-optic cable
Fibre-optic cables are made up of many thin glass strands (or fibres), which transmit data as
pulses of light. As they use light to transmit data, they do not suffer from electrical interference.
Fibre-optic cables do not break easily as they are strong, flexible and do not corrode.
Fibre-optic cables have a very high bandwidth of up to 100 terabits per second (Tbps) and are
capable of transmitting data over distances of 100 kilometres or more. For this reason, they are
often used to connect WANs across large geographic areas. The cables that cross the oceans
to connect different continents to the internet are fibre-optic cables.
Fibre-optic cable is more expensive to install than copper cable and is therefore used to
transmit data over long distances and to connect WANs.
Wireless networks
Wireless networks make use of radio waves to connect devices, and include technologies
such as Wi-Fi and Bluetooth.
The strength of a radio wave decreases as it moves further away from its transmission source, so
the radio waves that are used in wireless networks are only suitable for relatively short distances
of up to 100 metres. Radio waves are also subject to interference from other radio signals of the
same or similar frequencies, and are partially blocked by physical objects such as walls.
However, radio waves are ideal for mobile devices as the device will be able to connect to the
network as long as it is in range of a wireless access point (WAP). Wireless networks generally
have a bandwidth of about 300 Mbps.
Knowledge check
6 Identify two ways in which a desktop computer may be connected to a home network.
7 Identify a type of medium suitable for connecting WANs across large geographic areas.
8 State two advantages of using a wireless network.
9 State two disadvantages of using a wireless network.
173
Network topologies
The way in which devices in a network are arranged and connected together is called the
network topology. Any device connected to a network is referred to as a node. There are
two common LAN topologies that you need to know about.
Tech terms
Switch/hub
Used to connect devices
in a wired network so
that data can be received
and forwarded to the
correct destination
device.
Node
The name for any
connection to a Figure 5.3 Star network topology
network.
Data collision A star topology is the most common network layout, and it tends to be fast and reliable
When two separate data because each client has its own connection to the central node. As data is only directed from
packets are in the same the central node to the intended computer, it helps to keep network traffic to a minimum,
place at the same time. and in turn this reduces data collisions.
The switch can screen data packets, rejecting any that are corrupt, which can increase security
on the network, and it is easy to add new devices as they simply need to be connected to the
switch. If the connection to one device on the network fails it is less likely that the rest of the
network will be affected.
However, star networks require a lot of cabling, as every computer is connected
individually, which can be expensive. If the central server or switch fails then so will the
entire network.
Star networks tend to be found in large organisations such as schools and businesses. They
are also found in home networks, especially those that are wireless, with all of the devices
connecting to a central router with a built-in wireless access point. They are an ideal choice
when trying to create a reliable network as a single computer failure does not affect the rest
of the network. It is also relatively easy to add extra devices, so the network has some size
flexibility.
174
Server Workstation
Terminator Terminator
Printer
All of the devices share this cable to transmit data to one another, with the data being sent to
all of the other nodes. Each node then has to decide if it should accept the data by inspecting
the destination MAC address (see page 180).
Only one node can successfully transmit data at any one time, as when multiple transmissions
are sent simultaneously, the data will collide and have to be re-sent. If this happens, both
computers will wait a random amount of time before trying to re-send their information,
which slows the network.
If for any reason the backbone fails, the whole network will fail.
Because of this, standalone bus topologies are not widely used, although they may be used
within hybrid network topologies. Bus topologies are suitable for temporary networks in a
single room, where the amount of data to be transmitted is low. They are cheap because much
less cabling is required compared to a star topology.
It is relatively easy to connect nodes to a bus network, and they are also easy to dismantle
when no longer required.
Knowledge check
10 State what is meant by a network topology.
11 Describe a star topology.
12 Explain one advantage and one disadvantage of using a bus topology.
Network protocols
All networks work in essentially the same way. A device prepares a data signal to send to
another device, and this is transmitted along cables or wirelessly until it reaches its destination
address. This transmission is controlled by protocols, which are essentially sets of rules that
all manufacturers and devices use.
175
Ethernet
Ethernet is the traditional set of protocols used to connect devices in a wired LAN. Ethernet
is not one protocol but a family of protocols. Ethernet protocols define how data should
be physically transmitted between different devices, using MAC addresses (see page 180)
Tech terms to determine which device the data should be sent to. Ethernet protocols also define what
Channel should happen if collisions occur on the network. Ethernet protocols can be used on copper
Each frequency band or fibre-optic cables
(2.4 GHz and 5 GHz) is
further broken down Wi-Fi
into smaller frequency Wi-Fi is a set of protocols that define how network devices can communicate wirelessly using
ranges, which wireless radio waves. Wi-Fi is not one protocol but a family of protocols. Wi-Fi is a trademark, and
devices can receive and the Wi-Fi standards determine the frequency band and channel that should be used, data
transmit data at. Using transmission rates and how devices should be authenticated when they attempt to join a
different channels allows network.
multiple devices to use
the same Wi-Fi signal Most Wi-Fi standards transmit data using radio waves in one of two frequency bands, either
without interfering with 2.4 GHz or 5 GHz. Signals transmitted on the 2.4 GHz frequency have a greater range but lower
each other. data transmission rates than those using the 5 GHz frequency.
Data packet The generic term for a wireless network is a wireless LAN (WLAN).
A chunk of data that is
sent across a network. Transmission Control Protocol (TCP)
Header Transmission Control Protocol (TCP) is a protocol that splits the data from applications
The part of a data into smaller data packets that can be sent across a network.
packet that contains Each packet is made up of a header and payload. The header contains the sequence number
details about the data of the packet and a checksum to allow the recipient device to check that it has been sent
packet, to make sure it correctly. The payload contains the actual data from the application that needs to be sent.
is transmitted correctly When a data packet is correctly received, an acknowledgement message is sent back to the
and can be reassembled server.
when received.
Payload User Datagram Protocol (UDP)
The part of a data packet
TCP is concerned with the accurate delivery and receipt of data packets that are ordered and
containing the data that
error checked. However, the User Datagram Protocol (UDP) is used by apps to deliver
the application wishes to
data more quickly by removing the acknowledgement to the sender that the data was safely
transmit.
received. Data is sent in a constant stream from the server, without having any checks to make
Checksum sure that the recipient has received the data correctly. It is frequently used for activities such as
A mathematical live broadcasts and online games where speed of delivery is vital. If packets are lost, the video
technique that checks or audio will continue to play, but will just become a little distorted for a moment.
for errors in data that
has been transmitted. Internet Protocol (IP)
The Internet Protocol (IP) defines how data packets should be sent between networks.
Every device connected to a network is assigned a unique IP address. This represents the
location of the device on the network, just like your postal address indicates where your home
is. This address consists of four 8-bit sections, each of which represents a number between 0
and 255. Each section is separated by a full stop. An example IP address is 194.83.249.5.
An IP header is added to each data packet containing the source and destination IP addresses
for that packet. Routers use this information to determine whether the packet’s destination
is on the local network or whether the packet needs to be passed on to another network.
Switches on the destination network direct the data to the correct node or device.
176
Knowledge check
13 Explain what is meant by a network protocol.
14 Identify the most appropriate protocol to be used when uploading a file from a
computer to a web server.
15 Identify the most appropriate protocol to use when web page communications
between a client and host need to be encrypted.
16 Explain the purpose of SMTP.
17 TCP and IP are two protocols used in network communications. State what the initials
TCP and IP stand for and describe the function of each protocol.
When data is sent, it passes down the 4-layer TCP/IP model, starting at the application layer.
As it passes from one layer to the next, the data is encapsulated and additional information is
added. When the data reaches its destination, the process is reversed to de-encapsulate the
data, starting with the link layer.
Protocols:
Internet layer
IP
This is where data is addressed and packaged for
transmission. It then routes the packets across the
network.
Protocols:
Link layer
Wi-Fi
This is where the network hardware such as the NIC Ethernet
(network interface card) and OS device drivers are
located.
There are several advantages to organising the protocols in this way. Firstly, it is possible for
one layer to be developed or changed without affecting any of the other layers. Software
and hardware manufacturers can specialise in understanding one layer without needing to
know how every other layer works. This means that devices made by different manufacturers
are compatible, giving the consumer more choice. It is also easier to identify and correct
networking errors and problems.
Knowledge check
18 Identify two of the layers within the TCP/IP model.
19 What is the purpose of the internet layer within the TCP/IP model?
20 Describe two advantages of using the 4-layer TCP/IP model.
21 Name three protocols which operate at the application layer.
178
Network security
It is very important that networks are kept secure, as they are more vulnerable to hacking than
standalone devices. If a hacker is able to gain access to a network through a single device, they
can use this to then gain access to other devices on the same network. This may allow them
to steal sensitive data, or to install malware on the network servers.
Network security is primarily concerned with preventing unauthorised people from
accessing the network. There are several approaches that are used to secure networks.
Authentication
Authentication is the process of confirming that a user is who they say they are. There are
several ways in which this can be done:
● Usernames and passwords are perhaps the most common method. A username and a
secret password are chosen by the user and when these are entered a computer system
can check that they match those of a known user. Systems are often set up so that the user
account is locked after a certain number of failed attempts, to prevent people trying lots of
passwords to get into someone else’s account.
● Possession of an electronic key, device or account is used as authentication since only one
person will have access to that particular device. Some computer systems will check that
an email address or phone number belongs to you by sending an email or text containing
a secret code.
● Biometrics is the use of measurements relating to biological traits. If your school uses
fingerprint scanners to identify you, you will have experience of this. Banks are increasingly
using voice recognition to authenticate users who use telephone services.
Two-factor authentication is where two of the above are checked simultaneously. For example,
you may log in to a system with a username and password (first method of authentication) and
are immediately sent a text message or email to respond to (second method of authentication).
Once a user has been authenticated, user access levels can be used to ensure that users can
only access the files and other resources that they need to.
Encryption
Encryption is used to prevent data from being of any use if it is intercepted and read.
Any data sent on the internet is potentially vulnerable to being hacked, and it is particularly
important that data such as credit and debit card numbers used for online shopping are kept
secure. Data that is transmitted wirelessly is particularly susceptible to being intercepted, and
so encryption is used to disguise the contents.
Encryption relies on the use of a key to encrypt and decrypt the data. An algorithm can
be used for this. A very simple form of encryption is called the Caesar cipher. This method
displaces letters by a known amount. For example, if the letters were displaced by 4 then the
number 4 would be the ‘key’. A displacement of 4 would produce the following look-up table:
plaintext A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
letter
cipher E F G H I J K L M N O P Q R S T U V WX Y Z A B C D
letter
An encrypted message such as ‘COMPUTING’ would be transformed into GSQTYXMRK.
The message would be sent along with the key ‘4’ to allow decryption.
179
The Caesar cipher is a simple form of symmetric encryption. This means that both the sender
and receiver share the same key. However, most websites use asymmetric encryption. This
involves the use of a pair of keys, a public key and a private key, which are uniquely paired when
they are created. Your public key can be shared with anyone and can be used by them to encrypt
a message to send to you. However, only your private key can be used to decrypt the message.
Firewall
A firewall is a network security device that monitors incoming and outgoing network traffic.
It is primarily designed to stop unwanted internet traffic from gaining access to a network, and
decides whether to allow or block specific traffic based on a defined set of security rules. For
example, executable files, or data sent from specific IP addresses, might be blocked to prevent
malware being installed on the system. In a similar way, firewalls can also prevent devices on a
network from accessing certain websites. For example, a company may block access to social
media sites that are not needed for work purposes. A firewall uses ports to let data in and out
of the network, and these can be opened and closed to control the flow of data.
Many operating systems include a firewall as part of the software. However, a firewall can also
be a separate hardware device, and is often also built into a router. The capabilities of firewalls
have changed dramatically in recent years and will continue to do so.
Key point
Remember – one hexadecimal digit represents 4 bits of data. So six groups of two hexadecimal
digits is 12 hexadecimal digits, which represents 12 × 4 = 48 bits.
MAC address filtering can be used to allow specific devices to access, or be blocked from, a
network. This can be done in one of two ways:
● A white list can be created, which will only allow devices on the list to connect to the
network. This is the more secure approach but requires each device to be added to the list
individually.
● A black list can be used, which will deny access for any devices listed.
Authentication, encryption, firewalls and MAC address filtering can all work together to
increase the security of a network. Authentication ensures that only authorised users are
able to access resources once they have successfully logged in. On wireless networks, data
transmissions are encrypted to ensure that even if they are intercepted, they cannot be
understood. The actual devices used to access a network are controlled via MAC address
filtering. A whitelist means that only known and approved devices can be used to access the
network, even if the user is authorised. Alongside these methods, the firewall monitors all
incoming and outgoing traffic, filtering out any data that doesn’t meet given criteria and thus
stopping access to the computer or network.
180
Knowledge check
22 Identify three methods which can be used to help keep networks secure.
23 Give an example of how two-factor authentication may be used when signing up to a
website.
24 Explain why sensitive data is encrypted before it is sent on the internet.
25 Explain the purpose of an IP address.
26 Explain the purpose of a MAC address.
181
fibre-optic cable ■ access to files and resources can be controlled for different
wireless networks
users
network topology
star network topology ■ user activity can be monitored.
182
Wired networks
Wired networks use copper or fibre-optic cables to connect the devices. They tend to be found
where the devices are fixed in one place and do not move around.
Copper cable:
■ consists of twisted copper wires
■ is relatively cheap to install within a small geographic area, such as a LAN within an office
building
■ has a bandwidth between around 100 Mbps and 1 Gbps, for a distance of up to about 100 metres.
Copper cable is already found in telephone networks and so can be convenient and cost effective
if a high bandwidth is not required.
Fibre-optic cable:
■ consists of thin glass strands/fibres
■ is more expensive to install and is used to transmit data over long distances and to
connect WANs
■ has a very high bandwidth of up to 100 Tbps.
Wireless networks
Wireless networks use radio waves to connect devices and are ideal for mobile devices.
The two most common wireless network technologies are Wi-Fi and Bluetooth.
Advantages of wireless networks include:
■ They are generally cheap to set up.
■ Users can connect and move around freely as long as they are in range of a wireless access
point (WAP).
■ Additional devices can be added easily.
■ They are generally less secure if the data is not encrypted before transmission.
Network topologies
A network topology is the way in which devices are arranged and connected together.
In a star network topology, each computer is connected to a central node, which can be a switch
or a server. It is the most common network layout.
183
Star networks:
■ reduce data collisions as data is only sent between the central node and intended computer
■ increase security because the central node can screen data packets
■ are robust – if the connection to one device fails the rest of the network is unaffected
■ are found in larger hybrid wired networks and most home wireless networks.
In a bus network topology, each node is connected to a single cable called the backbone, with
terminators at each end. All devices share this cable to transmit data, with data sent to all of the
other nodes. Bus topologies are generally only suitable for temporary networks in a single room.
Server Workstation
Terminator Terminator
Printer
Bus networks:
■ are more prone to data collisions as each device sends and receives data using the backbone
■ are less secure as each device sees all data packets
■ are less robust – if the backbone fails the whole network fails
■ require less cabling
■ are found in hybrid networks and very small wired networks.
184
Network protocols
Protocols are sets of rules or standards that all manufacturers and devices use to communicate
with one another.
Two families of protocols are used to connect devices within a LAN.
Ethernet Ethernet is a set of protocols used to connect devices in a wired LAN.
Wi-Fi Wi-Fi is a set of protocols that is used to connect devices using radio
waves. Wi-Fi is a trademark and the generic term for wireless networks
is WLAN.
There are a range of standard protocols used by applications such as web browsers and email
clients.
HTTP Hypertext Transfer Protocol defines the rules to be followed by a web
browser and a web server when requesting and supplying information.
HTTPS Hypertext Transfer Protocol Secure uses SSL to encrypt
communications between a web browser and a web server to ensure
that they are secure.
FTP File Transfer Protocol defines the rules for transferring files between
computers.
SMTP Simple Mail Transfer Protocol defines the rules for sending email
messages from a client to a server, and then from server to server.
IMAP Internet Message Access Protocol allows multiple devices to have
synchronised access to mail on a mail server. Messages are read rather
than downloaded and can be organised and flagged.
185
Network security
Network security is concerned with preventing unauthorised access to networks. A combination
of different methods is usually used to control access to networks, and then to protect data
sent across networks.
Authentication is the process of confirming that a user is who they say they are. The simplest
method involves the user inputting a username and password. Additional factors can be used to
make the authentication process more robust, such as the use of biometrics or a code sent to a
device in the user’s possession.
Encryption is used to disguise the contents of data when it is transmitted to prevent it from
being of any use if it is intercepted. It involves the use of a key to encrypt and then decrypt the
data. It is especially important that encryption is used on wireless networks.
Firewalls monitor incoming and outgoing data on a network and decide whether to allow the
data through or to block specific traffic based on a defined set of security rules.
MAC address filtering allows devices to access, or be blocked from accessing, a network based
on the physical MAC address embedded within the device’s network adapter. (A MAC address is
a unique number associated with a device when it is manufactured and it cannot be changed.)
186
QUESTION PRACTICE
5 Fundamentals of computer networks
01 01.1 Draw a simple diagram to show a bus topology for five computers. [2 marks]
01.3 Identify two ways in which the computers could be connected together. [2 marks]
01.4 State whether the computers will be connected in a LAN or a WAN and
justify your answer. [2 marks]
02.3 Identify two protocols used in the transport layer to transmit data over
a network. [2 marks]
02.4 Complete the table by identifying one protocol found in each layer of
the TCP/IP model. [4 marks]
Layer Protocol
Transport
Link
Internet
Application
03.2 Identify and describe three reasons why a large company would choose
to use a star topology. [6 marks]
03.3 Explain how MAC address filtering can be used to protect a network. [3 marks]
03.4 Identify and describe two other methods that can be used to help keep
a network secure. [4 marks]
04 04.1 A small business has three employees, each with a computer, and a
printer that they share. They wish to connect these together to form a
LAN. Identify which topology would be most suitable for them to use
and justify your choice. [3 marks]
04.2 A school network uses a star topology. Explain why this is more
appropriate than a bus topology. [3 marks]
187
CYBER SECURITY
Malicious code
Malicious code, also known as malware, is any kind of malicious program that is installed on
a computer system with the intention to cause damage and disrupt its functionality or to steal
information.
The main types of malware include computer viruses, trojans and spyware. We will be looking
at these in more detail later in this chapter.
Pharming
Tech terms Pharming is a form of attack where users of a website are directed to a fake version of the
website.
Domain name There are two ways in which this might happen. Malware installed a computer can change the
A website address, IP address of the domain name to the bogus one, or malware can infect the DNS server itself
for example so that everyone is directed to the bogus site.
hoddereducation.co.uk.
In both cases, the user will enter the genuine website address into their browser, but will be
DNS server directed to the fake website, which usually looks exactly like the real one. Here, the user’s login
A server that contains details and personal data will be captured and these details can be used by the criminal to
details of the IP access the user’s real account. This is a particular concern for online banking and e-commerce
addresses associated websites.
with domain names.
Brute force attack
When hackers use
Weak and default passwords
thousands of random Passwords are commonly used to help prevent unauthorised access to a network or computer.
combinations of However, they are only effective if they remain secret and are not easy to systematically guess
characters every second by brute force attacks. They should not be used for multiple accounts and should never be
in order to guess written down.
passwords. A brute force attack is where a hacker systematically tries combinations of letters, numbers
Dictionary attacks and symbols in order to discover a password. These attacks are often automated, enabling
When hackers use thousands of combinations to be tried every second. Dictionary attacks work in the same
known words and way but use lists of known passwords and standard words in the dictionary.
previously leaked A weak password is one that can be easily discovered or detected by people who should
passwords to guess not know it. Examples of weak passwords include words picked out of the dictionary, simple
passwords. It is for this patterns of letters from a computer keyboard, car registration numbers, or the dates of birth
reason that you should and names of family members or pets.
never use just one Long passwords that use a combination of letters, numbers and symbols will take longer to
standard word as your guess in a brute force attack.
password.
Most computer systems and devices provide the user with a default password when they are set up.
Many systems prompt or force the user to change the password when they first log in. However, a
number of devices, such as routers, do not routinely require the password to be changed and the
password can often be found in the instruction manual or even on the device itself.
If a default password is not changed, it leaves the system far more vulnerable to unauthorised
access.
189
Removable media
Removable media refer to storage devices such as USB memory sticks, external hard drives
and CDs or DVDs. These devices pose two separate threats to computer systems: data theft
and virus infection.
Data theft can include both intentional theft of data, where an employee deliberately copies
sensitive data onto removable media to pass on to a third party, and unintentional loss of data,
where removable media containing unencrypted data are lost and fall into the wrong hands.
If removable media contain malware, it will attempt to install itself when connected to
a computer. It can then quickly spread to all other devices on the network unless suitable
security measures, such as anti-malware software, are in place.
For these reasons, many organisations prevent the use of removable media on their computer
systems.
Penetration testing
Penetration testing is used to test a system or network in order to identify vulnerabilities
in its security that an attacker could exploit.
Testers take on the role of hackers and try to gain unauthorised access in a controlled
attack. Good penetration testing also assesses the security awareness of users to see how
likely they are to fall for social engineering ploys, and demonstrates the effectiveness of
network security policies. It may also include checking the organisation’s ability to respond
to security incidents and to recover any data that has been lost or compromised following
an attack.
190
Knowledge check
1 Explain what is meant by cyber security.
2 Explain what is meant by pharming.
3 Identify three different types of malware.
4 Explain what is meant by a ‘weak’ password and give one example.
5 Explain what is meant by a ‘strong’ password.
6 Identify two threats that removable media pose to a network.
7 Describe the difference between white-box and black-box penetration testing.
Social engineering
The people that use computer systems are always the weakest point in security as they
can be influenced and exploited by others into making errors. Social engineering involves
manipulating people into doing things that they would not normally do by exploiting their
natural inclination to trust what they are being told.
Blagging
Blagging, also known as pretexting, is often done by phone but can also be carried out face
to face.
Here, the criminal invents a scenario to persuade the victim to divulge information or perform
actions that they would be unlikely to do in ordinary circumstances. Often, they will pretend
to be from an official organisation such as a bank, insurance company or the police, or to be
another employee of a company or a network administrator.
Phishing
Phishing uses fake emails, Short Message Service (SMS) messages and websites to trick
people into giving away their sensitive data and information (when an SMS message is used it
is sometimes referred to as smishing). Emails or messages usually claim or appear to be from a
bank or building society, an e-commerce site or an email provider.
The messages often ask the user to verify their account by clicking on a link or taking some
other similar action. Links often then take the user to a fake version of the website where
login details can be captured, and sometimes credit and debit card details. The cybercriminal
is then able to use these details to access the real account to steal a person’s identity or
money.
191
Shouldering
Shouldering, or shoulder surfing, involves finding out login details, passwords and
personal identification numbers (PINs) by watching people enter them.
This could happen by looking over someone’s shoulder as they enter their PIN at a cashpoint
or checkout, or even by using recording equipment. For this reason, we are encouraged to use
our other hand to cover the keypad as we type in our PIN. When logging in via a computer
screen, each character is replaced by an asterisk (*) to help mask what is being typed.
● Always using your hand to cover the keypad when typing in a PIN at a cash point or when
using a chip-and-PIN machine.
192 ● Never divulging a PIN over the phone, even if the caller claims to be from your bank.
Knowledge check
8 Define social engineering.
9 Identify three different social engineering techniques.
10 Explain how shouldering is carried out.
11 Blagging is a form of social engineering. Describe how it is used to gain personal data.
Malicious code
Malicious code, or malware, is software that has been written with the intention to cause
damage and disrupt the functionality of a computer system or to steal data. It is usually
installed without the user’s knowledge. Malware is the term used to refer to any kind of hostile
or intrusive software.
Viruses
A virus is a computer program that is hidden within another program. The virus code is only
run when the host program is executed.
Viruses can delete data or change system files so that data becomes corrupted. Some viruses
fill up the hard drive/SSD so that the computer runs very slowly or becomes unresponsive.
Viruses can replicate themselves and insert themselves into other programs, which can then
be passed on. They are often spread through attachments to emails, but may also be spread
through files, programs or games downloaded from a web page or by loading an infected
memory stick or CD/DVD.
To avoid the risk of introducing viruses to a computer system, it is important that users avoid
opening emails and attachments from unknown sources, or using unidentified memory sticks.
Anti-malware software is designed to detect and remove malware. It protects systems in
several ways:
● It performs real-time scans of incoming network traffic to detect whether they have been
infected with a virus.
● It performs periodic scans of the whole system looking for malicious applications.
Trojans
Trojans are programs that users are tricked into installing under the pretence that they are
legitimate and useful. They are often free and the malicious code hidden inside them only
becomes apparent once the software has been installed.
Some Trojans are just annoying, changing the desktop layout and adding new icons, but they
can also delete files and use back doors to send screenshots and key presses to a hacker’s
computer, allowing them to access your personal information.
To avoid installing Trojans, it is important to only download and install programs from trusted
websites and companies.
193
Spyware
Spyware is malware that comes packaged with other software, such as free software that a
user downloads.
It gathers information about a user and sends it to the originator. It includes programs such
as keyloggers that record all the user’s keystrokes allowing the originator to obtain passwords
and other login details.
Most anti-virus software will also detect spyware, but it is possible to get software specifically
designed to detect and remove spyware. As with other forms of malware, users should always
be cautious about downloading and installing free software.
Knowledge check
12 Match the type of malware to the description of how it is spread.
Virus Malware disguised as legitimate software
Spyware Malware that comes packaged with other software
Trojan Malware that is spread through infected files
13 Explain how anti-malware software helps to protect a system.
Biometric measures
Biometric security makes use of a person’s unique physical features, such as fingerprints,
facial recognition, voice recognition or even a retinal scan, to authenticate them and allow
them access to a system. Fingerprint scanners are a common security feature on many mobile
phones, tablets and laptops, and facial recognition is also used to unlock a range of devices.
Biometric methods cannot be stolen or forgotten and so are much more secure than passwords.
Password systems
As discussed earlier, passwords are a common method used to help prevent unauthorised
access to a network or computer. It is very important that passwords are strong and that they
are not written down anywhere.
Some systems ask for certain characters from a password, such as the 2nd, 3rd and 7th
characters, rather than requiring users to enter the whole password. This helps to prevent
spyware such as keyloggers from capturing full password details.
In addition to entering their username and password, two-step authentication requires the
user to enter a unique code sent to their phone or via an external app. The code is usually
only valid for a short period of time, and requires the user to have a phone in their possession,
making it much harder for a hacker to gain access.
194
CAPTCHA
A CAPTCHA is a form of challenge–response test used to determine whether a user is
human. It involves asking the user to complete a task that a software bot cannot.
The most common type of CAPTCHA is the text CAPTCHA, where the user is shown a series
of distorted characters as an image, which they have to type into a form. It is usually possible
to hear an audio version of the characters instead.
Picture recognition CAPTCHAs show the user a series of images from which they have to
select those containing a subset of images, such as all those that include cars.
Other types of CAPTCHA simply require the user to tick a box to confirm that they are not
a robot.
CAPTCHAs are effective in preventing fake registrations on websites, and other forms of spam.
However, some people find them quite challenging to read, and may be put off using a website
as a result.
Email confirmations
When signing up to a new website or service, users often receive an email asking them to
confirm that they want to set up the account by clicking on a link. The account will not be
registered and activated until the user has clicked on the link and finished the registration
process.
This system is beneficial to both the user and the website. It helps to confirm that the email
address is valid and prove the identity of the user as they need to be able to access their email
in order to complete the process. It also alerts users to attempts to use their email address
fraudulently.
Knowledge check
14 Identify and describe two methods that can be used to ensure that users are real when
signing up to a website.
195
196
Penetration testing
Penetration testing tests a system or network in order to identify vulnerabilities in its security
that an attacker could exploit.
Testers take on the roles of hackers to test how easy it is to gain access to systems or
resources without the knowledge of usernames, passwords or other normal means of access.
A white-box penetration test is designed to simulate a malicious insider who has knowledge of
the target system and is likely to have basic credentials to gain access.
A black-box penetration test is designed to simulate an external hacking or cyber-warfare
attack, where the attacker has no knowledge of any usernames, passwords or other normal
means of access for the target system.
Social engineering
Type of social engineering Methods
Blagging (or pretexting) ● The criminal invents a scenario to engage the targeted
victim.
● Victims are persuaded to divulge information or perform
actions that would be unlikely in ordinary circumstances.
Phishing ● Fake emails, SMS messages or websites are used to trick
people into giving away their personal data.
Shouldering ● Observing over the shoulder of a person as they enter details
such as their password or PIN.
Malicious code
Malware is software that has been written with the intention to cause damage and disrupt the
functionality of a computer system or to steal data. Malware refers to any kind of hostile or
intrusive software.
Anti-malware software, such as anti-virus software, is designed to detect and remove malware.
However, users should avoid downloading and installing programs from untrusted websites and
companies, and avoid opening email attachments from unknown sources, to prevent malware
being introduced into systems in the first place.
197
198
01.1 Discuss the benefits of the use of user access levels for the network
administrator. [4 marks]
01.2 Explain how penetration testing can be used to ensure that the network
is secure. [2 marks]
02.2 State three rules that a password policy should include. [3 marks]
02.3 Explain two other security measures that can be taken help keep a
system secure. [4 marks]
199
200
The above table has three fields and four records. The StudentID field, however, has a
special purpose – it is the field that uniquely identifies the record. No other student may have
the same StudentID as another student. The field that uniquely identifies a record is known
as the primary key field and each table should have one.
So far, this table is well organised. However, if we extend the table to also store data about the
registration class that each student is in, we quickly run into problems.
Table 7.2 Table called ‘StudentRegistration’ now including registration classes
StudentID FirstName Surname RegClass Teacher Room
027341 Bradley Jenkins 9A Mr Craddock Room 7
027342 Jamie Cable 9A Mr Craddock Room 8
027343 Charlotte Pegg 10B Mr Thompson Library
027344 Imogen Fletcher 10B Mr Thompson Library
Now that the table stores data about both students and registration classes, we run into the
problems of data redundancy and data inconsistency.
● Data redundancy is where data is repeated in a database table. For example, we know
that group 9A is taught by Mr Craddock and 10B is taught by Mr Thompson, but this is
shown more than once. If we extended the number of records in the table to include data
about all of the students in the school, this same information would be stored once per
student in each class. This makes the database file much larger than it needs to be.
● Data inconsistency leads on from data redundancy. If data is stored multiple times, what
if it isn’t always the same? An example of this is shown in the table above – is Mr Craddock’s
class in Room 7 or Room 8? The more redundant data there is, the more likelihood there is
that errors are introduced and that some of that data will be inconsistent.
Relational databases
A relational database is made up of more than one table. This removes the problems of
data redundancy and data inconsistency.
Using the previous example, we can split the ‘StudentRegistration’ table up into
two separate tables – one to store data about students, and one to store data about their
registration classes.
Table 7.3 Student table
StudentID FirstName Surname RegClass
027341 Bradley Jenkins 9A
027342 Jamie Cable 9A
027343 Charlotte Pegg 10B
027344 Imogen Fletcher 10B
201
Each table stores data about a different type of object, person, thing or idea. In this example,
the first table stores information about students and the second table stores information
about registration classes.
The primary key of the Registration table is the RegClass field – no two registration
classes can have the same value for this field.
Key point To link the tables together, the primary key from the Registration table is included in the
A relational database uses Student table; such a field is known as the foreign key of the Student table.
multiple tables, linked Relational databases may have more than two tables. Some complex database systems may
through primary and foreign have over a hundred tables! The important idea is that each entity (that is, a type of real-world
keys. The benefit of this thing) has its own table and each table refers to only one entity.
type of database is that data
With this in mind, we could expand the student database system with another table, this time
is not duplicated, which also
to tell us more about the rooms that are used by each registration group. A room table could
means that data cannot be
inconsistent. use the name of the room as the primary key and tell us all we need to know about each room.
For example:
Table 7.5 Room table
RoomCode Location IT_facilities
Room 2 Geography block True
Room 5 Maths block False
Room 7 IT block True
Room 21 IT block True
Library Sixth form centre False
In this example, the primary key of RoomCode is the foreign key in the Registration
table. This also gives the benefit of being able to store data about rooms that are not used for
registration lessons.
Knowledge check
1 State the meaning of the following terms:
(a) Foreign key
(b) Primary key
(c) Table
(d) Record
(e) Relational database
202
Worked example
Using the Student table from the previous section as a guide, the FirstName and
Surname fields for all students can be shown by using this SQL query:
ELECT FirstName, Surname
S
FROM Student
Tech term
Wildcards FirstName Surname
Special characters that Bradley Jenkins
can substitute for letters Jamie Cable
in searches. Charlotte Pegg
Imogen Fletcher
To find the same data, but sorted into ascending order of surname, an ORDER BY
keyword can be added:
ELECT FirstName, Surname
S
FROM Student
ORDER BY Surname ASC
FirstName Surname
Jamie Cable
Imogen Fletcher
Bradley Jenkins
Charlotte Pegg
To show all fields, but only those students in Registration class 10B, a WHERE clause would
be used:
ELECT *
S
FROM Student
WHERE RegClass = "10B"
203
Knowledge check
2 The table called Address_book contains the following data:
First_name Last_name Telephone Email
Manjit Wilson 02223334445 [email protected]
Kyle Mills 02232232232 [email protected]
Harry Smith 01223123123 [email protected]
Sheila Jones 01212121212 [email protected]
204
In the Student table above, the RegClass field is a foreign key that links to the RegClass
field as the primary key in the Registration table. Therefore, the additional WHERE clause
that would be needed to link and search these two tables is:
WHERE Student.RegClass = Registration.RegClass
Note that the table names are used before the field names; this is because the field names are
identical so it is important to differentiate them.
A query to link the tables together and show details from both linked tables would look like
this:
SELECT FirstName, Surname, Student.RegClass, Teacher
This would return the following data, as Mr Craddock is the teacher for 9A and Mr Thompson
is the teacher for 10B:
Notice that the Teacher field is contained in the Registration table and the other fields
are from the Student table.
If only certain records are required, the WHERE clause can specify further criteria using the
Beyond the AND keyword. For instance:
spec
SELECT FirstName, Surname, Student.RegClass, Teacher
There is another way FROM Student, Registration
to join tables together,
using a JOIN keyword. WHERE Student.RegClass = Registration.RegClass
AQA GCSE Computer
Science students are not AND RegClass = "9A"
expected to know about
the JOIN keyword – FirstName Surname RegClass Teacher
but if you are familiar Bradley Jenkins 9A Mr Craddock
with it and want to use Jamie Cable 9A Mr Craddock
JOIN in your answers,
this will be accepted. This is the same search as before but this time only students in RegClass 9A are returned
from the search.
205
Worked example
Using the Room table from the previous section as a guide, a new room can be inserted
into the table using the following SQL:
NSERT INTO Room (RoomCode, Location, IT_facilities)
I
VALUES ("Room 27", "Science corridor", True)
Existing data can also be updated using the UPDATE and SET keywords. It is important when
using this to also include a suitable WHERE clause to decide which records will be updated, or
all data in the table may be changed!
Worked example
To update all of the rooms in the IT block to instead be in the Computer Science block, the
following SQL can be used:
PDATE Room
U
SET Location = "Computer Science block"
WHERE Location = "IT block"
206
Data can also be deleted from a table using the DELETE FROM keywords. As with the
UPDATE keyword, it is important when using this to also include a suitable WHERE clause to
decide which records will be deleted.
Worked example
To delete all of the rooms that do not have IT facilities, the following SQL can be used:
ELETE FROM Room
D
WHERE IT_facilities = False
Knowledge check
3 What do the following SQL command words do?
(a) SELECT
(b) WHERE
(c) FROM
(d) INSERT INTO
207
database table.
● Data inconsistency is where repeated data is contradictory, so
users of the database do not know what the actual correct value
should be.
208
● ORDER BY is an optional command that allows the programmer to sort the data returned
into ascending or descending order using the ASC or DESC keywords.
For example:
SELECT names, points, bonus
FROM games
WHERE points > 100
ORDER BY names DESC
209
(ii) SELECT RecordID, ItemName, Supplier FROM sales WHERE Price < 1.00
(iii) SELECT RecordID, ItemName FROM sales WHERE QuantityStock > 1000
01.2 Write a query to print out the RecordID, ItemName and Supplier for
all items where the stock level is less than 50. [4 marks]
02.1 SELECT City, Population FROM Cities WHERE Currency = "UKP" [1 mark]
02.2 SELECT City, Country FROM Cities WHERE Population > 1500 [2 marks]
02.3 The city and population for all cities where the
currency is the euro. [4 marks]
02.4 All the data about any city with a population less than 1000. [4 marks]
210
211
Ethics are to some extent a personal thing but there are codes of ethics laid down by various
organisations including associations of computing professionals. The BCS (British Computer
Society) has some fairly typical ethical standards that it recommends computing professionals
should adhere to. They include not undertaking work that is beyond the individual’s capability,
not bringing the profession into disrepute, avoiding injuring others and not taking bribes.
Another organisation, The Computer Ethics Institute, lists ten commandments for computer
ethics:
1 Thou shalt not use a computer to harm other people.
2 Thou shalt not interfere with other people’s computer work.
3 Thou shalt not snoop around in other people’s computer files.
4 Thou shalt not use a computer to steal.
5 Thou shalt not use a computer to bear false witness.
6 Thou shalt not copy or use proprietary software for which you have not paid.
7 Thou shalt not use other people’s computer resources without authorisation or proper
compensation.
8 Thou shalt not appropriate other people’s intellectual output.
9 Thou shalt think about the social consequences of the program you are writing or the
system you are designing.
10 Thou shalt always use a computer in ways that ensure consideration and respect for your
fellow humans.
Legal impacts
The widespread use of computers has had a legal impact, meaning that new laws have had to
be constructed in response to technological changes. Computers are associated with a wide
range of existing and new criminal activities including:
● unauthorised access to data and computer systems for the purpose of theft or damage
● identity theft
● software piracy
● fraud
Various laws describe the rules that computer users must obey. These laws are designed to
prevent the misuse of computer systems and they can vary from country to country. It is a
criminal offence to not follow laws.
with specific exemptions, must register with the Information Commissioner’s Office and
disclose what data they are holding, why they are collecting it and how it will be used.
The seven principles of the DPA are:
● Lawfulness, fairness and transparency: There must be valid reasons for collecting and using
personal data.
● Purpose limitation: The purpose for processing the data must be clear from the start.
● Data minimisation: Data being processed must be adequate, relevant and limited to what
is necessary.
● Accuracy: Steps must be taken to ensure data is accurate, up to date and not misleading.
● Storage limitation: Data must not be kept for longer than necessary.
● Security: There must be adequate security measures in place to protect the data held.
● Accountability: The data holder must take responsibility for how the data is used and for
compliance.
Exemptions are granted to specific sectors including national security, scientific research,
financial services and the Home Office.
Environmental impacts
The use of technology also has an environmental impact. Most modern computers
consume low levels of electricity but are often left running permanently. Data centres, which
are large facilities that store all sorts of data (like Instagram accounts, YouTube videos, etc.),
account for around 2% of all energy used on the planet – this is the same amount as for air
travel. In addition, energy is of course also used to manufacture a computer in the first place.
As with all consumer electronics, computers are made from valuable physical resources such
as metals and minerals, some of which are very rare and non-renewable. Computers also
include some pretty toxic material, such as airborne dioxins, polychlorinated biphenyls (PCBs),
cadmium, chromium, radioactive isotopes and mercury. Their disposal raises environmental
issues and needs to be handled with great care.
Unfortunately, old computer equipment is often shipped to countries with lower environ
mental standards, to reduce the cost of disposal, and they end up in landfill sites. In
213
some cases, children pick over the waste to extract metals that can be recycled and sold, thus
exposing them to significant danger.
Figure 8.1 Discarded computer equipment is often picked over to extract metals
However, there are also a number of positive effects on the environment from computer use,
including:
● A reduction in the use of paper, with on-screen reading replacing the need for physical
copies of documents.
● Laptops and the internet allow people to work from home, reducing the need for travel
which reduces energy consumption and CO2 emissions.
● Computers are essential tools for scientific research into the development of renewable
energy and more energy-efficient devices.
● Smart metering constantly monitors and accurately reports energy and water use.
● Computers are also essential for the management of renewable and low energy-use
technology.
Privacy issues
Most people agree they have a right to some degree of privacy. However, we often provide lots
of personal information to organisations whenever we access the internet, particularly when
signing up to services with accounts. Organisations may even share this information with third
parties – which we may have accidentally agreed to when we set up an account.
Personal details and details of activities are often willingly shared on social media. People do
not always realise how much personal information they are sharing and exactly what can be
seen by whom. For instance:
● Whenever we check in on social media the location and time is logged.
Whenever we take a picture with our phone’s camera, the location and time are also logged.
When such images are uploaded to social media sites, the companies are able to access this
information and automatically scan images to try and work out who was in the picture
through facial recognition algorithms.
214
Knowledge check
1 Is it reasonable for organisations to demand access to and monitor social network pages
where the content is posted from private computers?
2 Discuss the environmental impact of computer use.
3 Identify two ways that individuals might be monitored in their daily life.
4 What issues may result from unwise posts on a social media site?
Cyber security
Cyber security is the technology used to protect networks, individual users and data
from attack or damage. The nature of these attacks and the measures to deal with them are
covered in Chapter 6. The Computer Misuse Act 1990 makes hacking and intentional damage
to computers or data illegal.
Ethical impacts Legal impacts Environmental impacts
Individual privacy and security Legislation: Computer Misuse Hacking industrial and public
Act utility systems may have severe
Identity theft
environmental consequences
Hacking and distribution of
Loss of or damage to personal
viruses are criminal acts
or corporate data
Mobile technologies
Mobile technologies are very useful and a key part of modern life, but they can be tracked,
and calls and messages can be intercepted and used by the authorities. This can be seen as a
positive when it comes to tracking criminal activity but as a threat to personal privacy.
Ethical impacts Legal impacts Environmental impacts
Sharing personal data can have Tracking criminal behaviour or Mobile devices use large
unforeseen and potentially tracking individuals amounts of rare and harmful
harmful consequences materials
Trolling and other illegal or
Personal privacy issues with abusive activities Many devices are not sent
tracking and use of data for recycling increasing the
demand for these materials
215
Wireless networking
Most places have extensive provision for wireless technology, most commonly to provide
internet access for mobile devices but also for smart monitoring of all kinds of infrastructure.
Smart metering is seen as having a positive impact on energy use.
Wireless technology can be vulnerable to attack, with messages (including sensitive information
such as passwords) susceptible to being intercepted. Attacks on wireless infrastructure
networks could cause widespread disruption of public services. See Chapter 5 for more details
about wireless networking and the use of encryption to protect data on these networks.
Ethical impacts Legal impacts Environmental impacts
Wireless networking can be Accessing data from wireless Wireless networking can be
vulnerable to eavesdropping networks would be an offence vulnerable to attack causing
providing access to sensitive under the Computer Misuse widespread disruption
and personal data Act
Cloud storage
Cloud storage is file storage that is accessed via the internet, meaning that data can be
accessed from any computer anywhere in the world. The drawbacks of cloud storage include
the need for internet access and the individual’s lack of control over the security of the files.
The security of data is the responsibility of the cloud service provider and the storage may be
in countries with different data protection laws. See Chapter 4 for more information about
cloud storage.
Ethical impacts Legal impacts Environmental impacts
Many people store personal Many data centres are Large data centres use a
information which may be outside the UK, EU or USA significant amount of energy to
vulnerable to hacking and and different data protection store vast quantities of data
misuse standards may apply
Hacking
Hacking is the unauthorised access to computer material and is covered by the Computer
Misuse Act 1990. Data stored on cloud servers may be more vulnerable to hacking than that
stored on physical media on the user’s own computer.
Ethical impacts Legal impacts Environmental impacts
The privacy of an individual The Computer Misuse Act Hacking of public utilities can
may be compromised from makes hacking illegal compromise systems causing
hacking, illegally accessing widespread disruption to
personal data public services
Wearable technologies
There are an increasing number of wearable technology devices such as activity monitors and
smart watches. These devices track movements and health data indicators, which are often
shared with friends, family and others via websites or apps.
Ethical impacts Legal impacts Environmental impacts
Personal privacy may be Illegally accessing this data is Wearable devices like all mobile
compromised through tracking outlawed in the UK under the devices use rare and harmful
of a wearer’s activity Computer Misuse Act materials meaning careful
recycling is important
216
Computer-based implants
Computer-based implants are often used for medical reasons, to assist with some conditions.
These include:
● to help with partial hearing
Autonomous vehicles
An autonomous vehicle is another name for a driverless car. The driverless car is becoming a
reality – there are many current trials of autonomous vehicles. While autonomous vehicles can
communicate with each other and cooperate effectively to provide a safe environment, there
are issues with these vehicles dealing with the less predictable behaviour of human drivers.
There are issues around the legal responsibility for any potential incidents – is the occupant of
the car responsible for what the computer system does, or is it the manufacturer of the car or
the programmer of the device?
It must be remembered that most car accidents currently are due to human error.
Ethical impacts Legal impacts Environmental impacts
Autonomous vehicles use In the case of an accident, who Where the majority of the
artificial intelligence (AI) to is responsible, the owner of the vehicles are autonomous,
monitor other vehicles and vehicle or the developer of the they can communicate and
road users; what happens to AI system used to operate the cooperate providing a more
that data? vehicle? efficient means of transport
Knowledge check
5 Write down two advantages and two disadvantages of using social media every day.
6 Identify two advantages of monitoring an individual’s internet searches for an online
store.
Key point
These topics are often asked as open-discussion questions in which you are expected to give a
balanced argument. Think about both sides of the issue and present a conclusion based on the
balance of the evidence. These questions may well be asked within a particular context, so make
sure your answers reflect this context rather than simply writing down a list of bullet points. It is
important to consider the point of view you are expected to take and respond based on evidence
seen from that person’s or organisation’s perspective. What may be an advantage from one point of
view may be a disadvantage from another.
217
Legal impacts
Legal issues are laws drawn up to govern activities and control
computer crime, and include:
■ unauthorised access to data and computer systems for the
purpose of theft or damage
■ identity theft
■ software piracy
■ fraud
Environmental impacts
The negative environmental impacts of widespread computer use
include:
■ There are large global energy requirements to run computer
systems and data centres.
218
■ Computers enable scientific research, which leads to more environmentally friendly technologies,
Privacy issues
Using computers raises concerns about individual rights to privacy. Ways in which individuals are
monitored include:
■ Companies can monitor exactly what their workforce are doing on their computers.
■ Use of CCTV and facial recognition.
■ Automatic number plate recognition (ANPR).
■ Websites can track a lot information about your internet activities: your location, your browser,
your IP address, your operating system, what websites you have visited and what you have
searched for. This data might be used to provide insights, for example to target advertising.
■ Mobile phone companies are able to track an individual’s location from their mobile phone, even
if they are not using it.
■ Mobile phone call records are also stored and can be accessed by law enforcement agencies if
requested.
■ With the wrong privacy settings, social media activity is available for anyone to see.
■ mobile technologies
■ wireless networking
■ cloud storage
■ hacking
■ wearable technologies
■ computer-based implants
■ autonomous vehicles.
219
02 Lots of people use wearable devices to track activity. Describe the advantages
and disadvantages to the individual when using these devices. [6 marks]
03 Driverless cars are becoming a reality. Discuss the main issues related
to the use of driverless cars, considering the ethical and legal aspects. [6 marks]
220
Colour depth The number of bits used for each pixel. Fetch–Execute cycle The basic operation of the CPU. It
Commenting Comments written by programmers. They are continually fetches, decodes and executes instructions stored in
ignored by the computer when the program is run but can make memory.
code much easier to understand. Fibre-optic cables Cables made up of thin glass strands which
Comparison operators Such as >, <, ==, etc., used to transmit data using light.
compare values. Field A single item of data in a record.
Compiler A translator that decodes all of the lines of code in a Field name The label given to each data field in a record.
high-level language to produce an executable file which can then File Transfer Protocol (FTP) A protocol for transferring files
be run by the computer. Programs only need compiling once. over the internet.
Computer network Two or more computers or devices that Firewall Software and/or hardware that inspects and controls all
are linked together to communicate and share resources. inbound and outbound network traffic.
Concatenation Joining two or more strings together to form Flowchart A visual way of representing inputs, processes and
one new string. outputs of an algorithm.
Constant A label for an area of memory that stores a value that Foreign key A field that relates to a primary key field in another
does not change during execution of a program. table.
Control unit (CU) A component of a CPU that coordinates the Hacking Unauthorised access to computer material.
activity of the CPU.
Hard disk drive (HHD) A non-volatile, magnetic storage
Copper cables Cables made up of eight individual copper wires device.
used for wired connections in a network.
Hardware The physical components of a computer.
Cyber security Technology used to keep networks, users,
Hexadecimal A number system based on 16, using digits 0–9
computers and data safe from attack, damage and unauthorised
and letters A–F to represent the decimal values 0–15.
access.
High-level language A programming language which
Database A persistent and organised store of data.
is written using English-like statements, that are easier for
Data inconsistency Where data is stored twice in a database programmers to work with. High-level languages, such as Python,
but with different values so the true value is unknown. Java, C# and VB.Net, must be translated into machine code before
Data redundancy Where the same data appears twice in a a computer can run them.
database, wasting space. Huffman coding A minimal variable-length character coding
Data structure A collection of data values given one name. based on the frequency of each character.
Data validation Limiting data that can be used by checking Hypertext Transfer Protocol (HTTP) A protocol used to
against rules. transfer data between a web browser and web servers.
Decimal A number system based on 10. Hypertext Transfer Protocol Secure (HTTPS) A secure
Declare Tell the language that the variable is to be used and give version of HTTP that adds Secure Socket Layer (SSL) encryption to
it a data type. the data.
Decomposition Breaking a problem into sub-problems. Identifier Another word for the name of a variable or constant.
Definite iteration Loop for a specified number of times, for Image size The width in pixels x height in pixels for an image.
example FOR loops. Indefinite iteration Loop until a particular condition is met, for
Efficiency The number of steps (and therefore time) required for example WHILE loops.
an algorithm to solve a problem. Input–Process–Output Problems and algorithms can be
Embedded system A computer system that forms part of an broken down into inputs, processes and outputs.
electronic device. Integer division (e.g. DIV) An operator that returns the
Encryption The process of encoding a message or information whole number after a division, for example 11 DIV 2 = 5.
so that only authorised persons can access and understand it. Integers Whole numbers, for example 302.
Erroneous test data Values that are of the wrong type, for Internet A global network of networks that connects computer
example a string when the value should have been an integer. systems together across the world.
Ethernet A protocol used to connect devices in a LAN over a Internet layer Layer in the TCP/IP model concerned with
wired connection. addressing and routing data packages.
Ethics Moral principles that govern a person’s behaviour.
222
Internet Message Access Protocol (IMAP) A protocol Modulus division (e.g. MOD) An operator that returns the
for accessing email messages on a mail server without having to remainder after a division, for example 11 MOD 2 = 1.
download them to your device. Nested iteration Iteration inside another iteration construct
Internet Protocol (IP) A set of rules for sending and receiving (such as a FOR loop within another FOR loop).
data across the internet. Nested selection Selection inside another selection statement
Interpreter A translator that decodes one line of code of (such as an IF within an IF statement).
high-level language and then runs it before moving on to the next Network security Methods used to prevent unauthorised
line. Programs need to be interpreted each time they are run. access to computer networks.
Iteration Repetition of sections of code. Network topology The way in which devices are arranged and
Layers A way of separating the different activities involved in connected together in a network.
communication over the internet. Nibble A group of 4 bits, half a byte.
Legal Actions permitted or denied by force of law. Normal test data Values that sit within the expected range.
Length (string) A string-handling operation that counts how NOT gate A NOT gate output reverses the input.
many characters are contained in a string.
Operating systems Software that communicates with the
Link layer Layer in the TCP/IP layer concerned with forwarding hardware and allows other programs to run.
data packets within a network.
Operators Symbols or words in a program that are reserved for
Local area network (LAN) A network of computers in a small particular actions.
geographic area, such as a single building.
Optical storage Storage devices that use laser light to read and
Local variables Variables that are only accessible inside the write data.
module where they are located.
OR gate An OR gate output is 1 if one or the other, or both, of
Logic circuit A circuit designed to perform complex functions the two inputs are 1.
using basic logic gates.
Parameters Values that a main program sends to subprograms
Logic error Something that causes the program to behave in an for them to use.
unexpected way.
Password systems A memorised set of characters used to
Looping Another name for iteration. confirm the identity of a user.
Lossless compression Compression technique that does not Patching A software update designed to update, fix or improve
lose any of the original data and the original file can be recovered. a program.
Lossy compression Compression technique that removes Penetration testing Testing a computer network for
some of the original data. The original cannot be recovered. vulnerabilities that an attacker could exploit. It is an authorised
Low-level language A programming language whose lines of activity also known as ethical hacking.
code directly correspond to the CPU’s hardware processes. This Personal area network (PAN) A computer network
means it has little or no abstraction, for example machine code, connecting devices near to an individual for their personal use.
assembly language.
Pharming A form of attack where users are directed to a fake
Machine code A language using binary codes that a computer website.
can respond to directly.
Phishing The use of fake emails or messages to obtain sensitive
Malware Software programs designed to cause damage to a data.
computer system or steal information. It is short for ‘malicious
Pixel The smallest element of an image. Pixels are the dots that
software’.
make the image on the screen.
Media Access Control (MAC) address A number
Prefixes: kilobyte (KB), megabyte (MB), gigabyte
programmed into the network interface controller (NIC) that
(GB), terabyte (TB), petabyte (PB) Naming convention
uniquely identifies each device on a network.
based on multiples of 1000.
Memory management The process in which the operating
Primary key A field that holds a unique value; its value is not
system assigns blocks of memory to programs that are running in
shared by any other record.
order to optimise system performance.
Processor cores Multiple processor cores may be able to
Mobile technology Technology that the user carries with
process multiple instructions simultaneously.
them, such as smartphones, tablets and smartwatches.
Program code Instructions given to a computer in a high-level
Modularised programming Splitting a program into separate
language.
modules to make implementation and maintenance easier.
223
Programming language A language used to write instructions Shouldering Also referred to as shoulder surfing, obtaining
for a computer. information such as a PIN by watching the person enter it.
Protocol Set of rules that determine how data is transmitted Simple Mail Transfer Protocol (SMTP) A protocol used to
between devices on a network. send emails from an email client, such as Outlook, to a mail server.
Pseudo-code Similar to a high-level programming language but Social engineering Methods used to trick people into
without strict syntax rules. divulging sensitive or confidential information.
RAM The main memory of a computer that stores data, Solid-state drive (SSD) A non-volatile storage device using
applications and the operating system while in use. When the solid-state storage.
power is turned off, RAM loses it’s data. Solid-state storage Storage device using electronic switches
Random numbers A number returned by a program that to store data.
cannot be predicted in advance. A series of random numbers Sorting algorithm: bubble sort, merge sort Different
would not display any patterns at all. algorithms that can sort a list of unordered data.
Read and write Data can be both read and written by the Software The programs that run on the computer.
computer.
Spyware Malicious software, such as keyloggers, that is designed
Read-only Data cannot be written by the computer. to gather data from a computer.
Real numbers Numbers with a decimal point, for example 4.0, SQL commands: SELECT, FROM, WHERE Used to
302.81. Also known as floating point numbers. interrogate databases.
Record A series of data fields. Star network topology A network arrangement where each
Registers Very small memory locations within the CPU that computer or client is connected to a central point, usually a switch
temporarily store data and can be accessed very quickly. or hub.
Relational database A database consisting of multiple linked String A collection of items from the computer character set, for
tables. example ‘hello’.
Relational operators See Comparison operators. String conversion Converting a string to another data type
Removable media Storage devices that can be removed from (such as an integer or Boolean).
a computer while it is running. String handling Modifying or manipulating strings, such as
Returning a value To pass a value back from a function. joining them together (concatenation) or finding their length.
Robust program A program that will not crash or malfunction Structured Query Language (SQL) The language used to
even when unexpected input is given by a possibly malicious user. pass instructions to databases.
ROM Read-only memory used to store data and programs to Substring A part of a string, for example the first three
initialise a computer system. characters of HELLO would be HEL.
Run-length encoding (RLE) Data compression technique Syntax error Something that breaks the grammatical rules of
that converts consecutive identical values into a code consisting of the programming language.
the character and the number of characters in that sequence. Systems software The files and programs that make up the
Sample A digital representation of an analogue signal at a operating system of a computer.
moment in time. Table A collection of records in a database.
Sample rate The number of times a sound is sampled per Test data Values that are used to check that a program behaves
second, measured in Hz. correctly.
Sample resolution The number of bits per sample. Testing Checking that a program does what it should for every
Searching algorithm: linear search, binary search possible input and output.
Different algorithms that can search a list of data. Trace table Records the values of variables and outputs for each
Secondary storage Non-volatile storage for files and line of code, used when checking a program to make sure it is
programs. correct.
Secure program A program that only allows access to Translator A program that decodes a high-level language into
authorised users. machine code. There are three types of translators: assemblers,
compilers and interpreters.
Selection The decision-making process in a program.
Transmission Control Protocol (TCP) A protocol that
Sequence Execution of statements in a program one after
splits the data from applications into smaller data packets that can
another.
be sent across a network.
224
Transport layer Layer in the TCP/IP model concerned with Von Neumann architecture The most common
controlling communication between two hosts. organisation of computer components, where instructions and
Trojan Malicious software that presents as legitimate software. data are stored in the same place.
Truth table A table listing all possible inputs and outputs for a White-box penetration test A test simulating a malicious
logic circuit. insider who has knowledge of the target system and is likely to
have basic access credentials.
Unicode A character set using 16/32 bits to represent a range
of language symbols. There are several billion possible character Wide area network (WAN) A network of computers that
codes available to Unicode. spans a large geographic area, often between cities or even across
continents.
User Datagram Protocol (UDP) A protocol used for
streaming data across the internet. Wi-Fi A set of protocols that allows devices to communicate
using radio waves.
Utility software A collection of programs, each of which does a
specific housekeeping task to help maintain a computer system. Wired networks Networks using cables to connect devices
together.
Variable A label for an area of memory that stores a value that
can change during execution of a program. Wireless access point (WAP) A device that allows devices to
connect to a network using Wi-Fi.
Virus Malicious software hidden within another program that
can replicate itself. Wireless networks Computer networks that use radio waves
to connect to devices, instead of cables.
Volatile and non-volatile Volatile means data is lost when the
power is removed. Non-volatile memory retains data even when XOR gate An XOR gate output is 1 if one or the other, but not
the power is turned off. both, of the two inputs are 1.
225
6 (a) Blueberry 15 Consider the data that a user could input (including
(b) Lime incorrect, unexpected or deliberately invalid data),
(c) fruit[1][2] dealing with these appropriately. Ensuring that all
7 (a) 16 instructions and error messages are unambiguous and
easy to follow.
(b) ‘Co’
(c) ‘g is fun’
16 Two factor authentication requires the use of two
different types of authentication. These are usually
(d) SUBSTRING(13,15,text) or
selected from something you know (such as a
SUBSTRING(13,len(text-1),text)
password), something you have (such as a code sent to
8 Functions return a value or multiple values to the main a mobile phone in your possession), or biometrics (such
program; procedures do not return a value.
as fingerprint scanners). For example, you may be asked
9 Subroutines allow programs to be split up into multiple to enter your password and then enter a code sent to
sections. They make the code easier to read and you in a text message.
maintain, reduce the size of the code and allow reuse of 17 Normal test data is data that is of the correct type that
code. They make it easier to debug code as errors as the you would expect a user to input. It should be accepted
scope is set by the subroutine. and not cause any errors.
10 Validation involves checking values against a set of rules 18 Boundary test data is of the correct type and is at the
to see if the data is sensible and as expected. It does not very edge of what should be accepted, allowing the
check that the data is correct. program to run without causing errors. Erroneous test
11 • A type check, to make sure that numbers are data is of the correct type but should not be accepted
entered. as it is not within the expected range.
• A range check, to make sure that the person is not 19 Any appropriate password that is less than eight
over 100. characters or more than 15 characters long (e.g. ‘bob’ or
• The use of drop-down lists so that users can only ‘please change me this password is too long’).
select from a pre-set range of values. 20
• A length check to ensure the data contains the right Test data Type of test Expected result
number of digits. data
12 It is not easy to validate a name because, apart from 25 Normal Accepted
checking for any unusual characters, such as %, the
length of someone’s name can vary greatly and there is (or any value over 18)
no set range that it would fall into. 18 Boundary Accepted
13 (a) When the user enters −10, the WHILE loop 15 Erroneous Rejected
repeats and asks the user to enter another value as (or any value under
the condition (withdraw ≤ 0) is True. The 18, or any value of the
program will not exit the loop until a suitable value wrong data type)
is entered. In addition, the message ‘you must 21 A logic error will still allow the program to run but will
withdraw a positive amount’ is displayed. produce an unexpected result, whereas a syntax error
(b) When the user enters 110, the WHILE loop will stop a program from running in the first place as it
repeats and asks the user to enter another value breaks the rules of the language.
as the condition (withdraw > balance) 22 This would cause a syntax error because FOR is a
is True. The program will not exit the loop until a keyword and so provides the start of a new construct
suitable value is entered. In addition, the message rather than completing the IF statement condition.
‘you cannot withdraw more than your balance’ is 23 This would cause a logic error. The program would still
displayed. run, but the result would be incorrect.
(c) When the user enters 60, the WHILE loop ends
as both conditions (withdraw ≤ 0 or
withdraw > balance) are False. The
3 Fundamentals of data
balance is then changed to be 40 (100 − 60) and
the new balance of 40 is output.
representation
14 Robust programming is ensuring that the program still 1 Computers use switches to store and process data and
functions correctly under less than ideal conditions. each of these switches have just two states: either 1 (on)
227
228
37 S = 10, W = 0011 1 0 0 0
38 13 1, 12 0, 7 1 (or in binary 10001101 00001100 1 0 1 0
10000111) 1 1 0 0
39 1 1 1 0
4 Computer systems 6
A B C P
1 0 0 0 1
A B C P 0 0 1 1
0 0 0 0 0 1 0 0
0 0 1 0 0 1 1 1
0 1 0 0 1 0 0 0
0 1 1 1
1 0 1 1
1 0 0 0
1 1 0 0
1 0 1 1
1 1 0 0 1 1 1 1
1 1 1 1
7
A
2 P
A B P B
0 0 1
8
0 1 0
A
1 0 1
P
1 1 1
B
3 C
A B P
0 0 1 9
0 1 0 A
P
1 0 0 B
1 1 0
4 10
A B C P A
0 0 0 1
B
0 0 1 1 P
0 1 0 1 C
0 1 1 0
D
1 0 0 0
1 0 1 0
1 1 0 0 11 P = NOT (A AND B)
1 1 1 1 12 P = (NOT A) OR (NOT B)
13 Programs that are not essential to the operation of
5 the computer, but which are involved in maintaining a
A B C P computer system.
0 0 0 1 14 • Encryption software
0 0 1 1 • Defragmentation
0 1 0 0 • Data compression
0 1 1 1 • Backup
229
15 To protect data from unauthorised access. The data is 27 An assembler converts assembly language into machine
scrambled into a form that cannot be understood if it code.
is accessed by unauthorised users. 28 A processor with four processor cores (able to deal with
16 The performance of a system is slowed as the disk four simultaneous processes).
needs to be accessed more frequently to read all of 29 The clock speed is 2.3 GHz. (It is able to carry out 2.3
the data. billion cycles per second.)
17 • To reduce the size of files so that they take up less 30 • It is used to hold data that needs to be accessed very
storage space. quickly.
• To reduce the size of files so that they can be • It sits between the CPU and main memory.
transmitted more quickly over the internet. • It is faster than accessing main memory.
18 • Provide a user interface. • CPU looks to cache for necessary data or instruction.
• Control the use of the RAM. • If the data is not in cache, it is found in main memory
• Share processor time between different programs then transferred to cache.
and processes. 31 • Clock speed determines how many operations per
• Control peripheral devices. second.
• Control who can access the computer and what • Cache memory holds frequently required data, so
resources they can use. more cache less time accessing main memory.
• File management to allow users to organise their • More cores allow more processes to complete
work into folders and subfolders. simultaneously, more cores more speed.
19 The memory manager controls whereabouts a program 32 To process data, carry out instructions and control the
and its data will be stored in RAM. When a program is components of the computer.
finished or the data is no longer needed, it frees up the 33 The processor
space for reuse. • fetches instructions from memory
20 These are programs which act as a translator to allow • decodes these instructions
the CPU and devices to communicate correctly.
• executes the instructions.
21 The processor manager schedules which processes are 34 To hold data currently in use by the CPU and addresses
to be executed by the CPU.
to fetch data from or store data in.
22 • User authentication in order to access software and 35 Any two from: arithmetic operations (add, subtract),
files.
logical operations (AND, OR, NOT) or binary shift.
• Use of different privileges and rights for different 36 • RAM is volatile, meaning it needs electrical power to
types of user.
operate – any data stored in RAM is lost when the
• Automatic updating of the OS to ensure that power is turned off.
security loopholes are patched.
• ROM is non-volatile memory, which means it does
• Malware protection from inbuilt utilities. not require power to maintain its contents.
• Automatic encryption of data stored on the • RAM is read-and-write.
secondary storage.
• ROM is read-only.
23 Any three from: Python / C# / C++ / Visual Basic / Ruby • RAM holds the operating system and applications/
/ Pascal / Fortran / Java / JavaScript or other suitable
data in use when the computer is switched on.
alternatives.
• ROM holds the data and instructions required to
24 • They use English-like syntax which makes them easier boot the computer up.
for programmers to use.
37 The operating system, applications that are running
• They use abstraction to hide the details of the and any associated data while the computer is on and
underlying instructions that need to be completed
in use.
by the processor.
38 The instructions and data needed to get the system up
25 They enable programs to be run very quickly. and running and ready to load the operating system
26 • Using an interpreter. This translates and runs the from secondary storage.
code one line at a time.
39 Because RAM is volatile, no data is stored in RAM once
• Using a compiler. This translates the whole program power is removed. We need secondary storage to store
into machine code and produces an executable file.
230
various files on our computers so that they are available • Backups can be managed centrally.
the next time we switch on the computer. 2 • Additional hardware is usually needed to set up.
40 The operating system, data, images, programs, • Networking hardware can be expensive.
documents. • Malware can spread easily between devices
41 Cloud computing refers to the use of storage, services connected to the network.
and applications that are accessed via the internet • If it uses a central file server, no one will be able to
rather than being stored locally on a device. access files if it goes down.
42 • File storage, such as DropBox, iCloud Drive. • Larger networks will need to be overseen by a
• Applications, such as Office 365, Google Docs. network manager.
43 • An internet connection is required to access the 3 A LAN is a network in a small geographic area, such
data. as a home, a school, an office or a group of buildings
• There is little control over the security of the data or on a single site. The hardware is usually owned and
where it is stored. maintained by the organisation that uses it. It will often
• Terms and process of data storage can be changed use both wired and wireless connections.
with little notice. 4 Bluetooth
• Fees may become expensive in the long term. 5 • A LAN is a network covering a small geographic area;
44 ROM is non-volatile and does not require power to a WAN covers a wide geographic area.
maintain its contents. It holds data and instructions • The networking hardware in a LAN is usually owned
to operate the device. RAM is required to store user and maintained by the organisation that uses it; the
selections or any output generated by the device. connections used in a WAN are usually hired or
45 • User selection for time, power level, program. leased from a telecommunications company.
• Display of user selections, timer countdown, ‘ping’. 6 Using ethernet cables or wirelessly using W-Fi.
46 Many examples including those in the book: 7 Fibre optic cable
washing machines, dishwashers, microwaves, set- 8 • They are generally cheap to set up.
top boxes, telephones, televisions, home security, • Most devices connect automatically.
water meters, energy smart meters, home security or • Users can move around as long as they are in range
heating monitoring systems, missile guidance, vehicle of the WAP.
management, CAM, digital cameras and portable • Additional devices can be added easily.
entertainment devices. (There are several other
9 • The speed of data transmission is slower than wired
examples.)
networks.
Justification based on device selected, but can include:
• Connections can be obstructed by obstacles.
• power requirements for example battery operated • Connections are often less stable than wired
devices
connections.
• size, for example in portable devices • Data packets can be intercepted and read if they
• rugged, for example in missiles or car engines have not been encrypted.
• low cost for domestic devices 10 The physical or logical arrangement of nodes that make
• dedicated software – limited need for user input and up a communication network.
output, limited range of programs/options. 11 Each computer or client is connected individually to a
central point, usually a switch or hub.
5 Fundamentals of 12 Advantages:
computer networks • Cheap to set up as less cabling is required compared
to other topologies.
• Relatively easy to connect devices.
1 • Can share hardware devices.
Disadvantages:
• Can share an internet connection.
• Only one node can transmit data at a time.
• Can exchange data between computers.
• If the backbone fails, the whole network will fail.
• Files can be stored centrally.
13 A set of rules that allows devices to transmit data to
• Software can be managed centrally.
one another.
• Security can be managed centrally.
14 FTP
231
15 HTTPS
16 Used to send emails to an email server, or from one
6 Cyber security
email server to another.
1 It is the different ways in which networks and devices
17 TCP stands for Transport Control Protocol. It splits
are protected against unauthorised access.
data into smaller packets and adds the header, which
includes the packet number, number of packets and 2 It is where users are directed to a fake website in order
checksum. IP stands for Internet Protocol. It defines to obtain their login details.
how data should be sent across networks, by including 3 Virus / Trojan / Spyware
source and destination IP addresses within each data 4 A password that can be easily discovered or detected
packet. by other people, such as names of family or pets / car
18 • Application layer registration numbers / simple patterns of letters from a
• Transport layer keyboard, for example qwerty.
• Internet layer 5 A long password (eight characters or longer) that
includes a mix of uppercase letters, lowercase letters,
• Link layer numbers and special symbols.
19 It addresses and packages data for transmission and
6 • They may introduce malware onto a network.
then routes the packets across the network.
• Data may be copied onto the device and stolen.
20 • It is possible for one layer to be developed or
changed without affecting any of the other layers. 7 White-box testing simulates an employee trying to hack
Software and hardware manufacturers can specialise into a system from the inside, with knowledge of the
in understanding one layer without needing to know system. Black-box testing simulates external hacking
how every other layer works. with no knowledge of usernames or passwords or how
the system operates.
• Devices made by different manufacturers can be
compatible, giving the consumer more choice. 8 It is the process of tricking or manipulating people into
giving away confidential information or access details.
• It is easier to identify and correct networking errors
and problems. 9 • Blagging
21 • HTTP • Phishing
• HTTPS • Shouldering
• FTP 10 Shouldering involves watching people as they enter
their login details or PIN number.
• IMAP
11 A criminal inventing a scenario to trick a victim into
• SMTP divulging information that they wouldn’t normally do
22 • Authentication otherwise.
• Encryption 12
• Firewall
Virus Malware that is spread through infected files
• MAC address filtering
23 A user sets up their username and password. They Spyware Malware that comes packaged with other
software
then have to enter their email address or mobile phone
number. A code is sent to their email address or mobile Trojan Malware disguised as legitimate software
phone which they have to enter on the website in order 13 • It performs real-time scans of incoming network
to gain access. traffic to detect if they are infected with a virus.
24 Encryption disguises the contents so that it cannot be • It performs periodic scans of the whole system
read if it is intercepted. looking for malicious applications.
25 • An IP address identifies a network or device on the • If it detected a virus or other malware, it is
internet. quarantined to prevent it from running and allows
• An IP address is added to identify the source and the users to attempt to clean or remove it.
destination. 14 • CAPTCHAs: Users are required to select a sub-set of
• The IP address is used to determine where to send images / enter text that has been distorted.
the data. • Email confirmation: Users are sent an email with a
26 A MAC address uniquely identifies each device that is link they need to click on to confirm that their email
connected to a network. address is valid.
232
7 Relational databases No
• Private posts from private computers.
and Structured Query • Individual has the right to their own opinions and
the right to free speech.
Language (SQL) 2 For example:
• Use of electricity by data centres.
1 (a) A foreign key is a key from one table stored in • Use of rare substances within the technology
another table to create a link between the tables. depleting resources.
(b) A primary key is a field that uniquely identifies a • Energy used to manufacture devices.
record in a table. • Toxic materials used and their disposal.
(c) A table stores data about a different type of object, 3 For example:
person, thing or idea.
• CCTV on the streets and in public places as well as
(d) A record is a data structure that allows multiple private homes with CCTV, corporate buildings with
data items to be stored in different fields, using CCTV and the workplace.
field names to identify each item of data.
• Mobile phones can be tracked and are tracked by
(e) A relational database is a database made up of various apps.
more than one table linked together.
• Online activity in the workplace and by various
2 (a) Manjit 02223334445 websites, for example to monitor searches to target
Kyle 02232232232 advertising.
Harry 01223123123 • Online monitoring of social media activity to provide
Sheila 01212121212 a profile for organisations.
(b) SELECT First_name, Email FROM 4 For example:
Address_book WHERE Last_name = • Social media posts are viewable by a wide audience
'Mills' often well beyond friends and acquaintances, and
(c) SELECT * FROM Address_book may influence how the individual is seen by potential
WHERE Email = '[email protected]' employers or members of specific groups or the
(d) SELECT * FROM Address_book general public.
ORDER BY Last_name ASC
• Families may see posts intended for close friends;
3 (a) Identifies the fields to return from the database. employers may see unguarded moments from social
(b) Allows the programmer to include criteria, with activities.
only matching records being returned. 5 For example:
(c) Identifies which table(s) the data will be returned • Sharing recent activities with friends.
from.
• Keeping friends up to date with what you like and
(d) Inserts new data into a table using the table are doing.
name and fields to specify where the data is to be
• Unguarded moments available to employers.
entered.
• Comments may solicit abuse, trolling.
8 Ethical, legal and 6 For example:
• Target advertising more effectively.
environmental impacts • Promote special offers.
of digital technology on
E.g. searches for shoes may solicit social media
advertising for various shoe brands or online retailers
wider society can provide better targeted promotions.
1 For example:
Yes
• The activity may reflect on the company.
• It may identify the individual’s opinions and activities
that are incompatible with the company.
233
Input choice
Yes
Choice A? Add
No
Yes
Choice B Delete
No
Yes
Choice C? Change
No
No
Choice D?
Yes
Stop
234
win ← USERINPUT
draw ← USERINPUT
win_int ← STRING_TO_INT(win)
draw_int ← STRING_TO_INT(draw)
OUTPUT points
04 04.1 Line 1 syntax error (number), should be initialised to 0.
Line 3 always references array index 1 rather than the variable number.
04.2
number ← 0
name[number] ← USERINPUT
number ← number + 1
ENDWHILE
OUTPUT number
OUTPUT name[number]
ENDFOR
OUTPUT name[number]
number ← number + 1
ENDWHILE
235
05
x y output
0 0
1 1
3 2
6 3
10 4
15 5
21 6
21
07 1 mark allocated to every correct swap. Marks indicate where a swap has been identified.
0. Pear Apple Grape Banana Strawberry Raspberry [1]
1. Apple Pear Grape Banana Strawberry Raspberry [1]
2. Apple Grape Pear Banana Strawberry Raspberry [1]
3. Apple Grape Banana Pear Strawberry Raspberry
4. Apple Grape Banana Pear Strawberry Raspberry [1]
5. Apple Grape Banana Pear Raspberry Strawberry
6. Apple Grape Banana Pear Raspberry Strawberry [1]
7. Apple Banana Grape Pear Raspberry Strawberry
09 09.1 1 mark per stage. For the first three stages, the algorithm compares the item searched for
(Harry) to the item pointed to and moves on because the item is not found. For the fourth
item, Harry is found and so the algorithm ends.
Jeremy, Adrian, Ben, Harry, Frank, James
09.2 The list is not sorted and so a binary search could not have been carried out.
10 10.1
AD245, BE767, FR226, HA102, HC224, JA233, KE124, MA267, PE334
HA102
1 mark for identifying the midpoint (HC224) and discarding the right-hand side of the list.
1 mark for identifying the midpoint of the new sublist (either BE767 or FR226) and
discarding the left-hand side of the list.
1 mark for continuing until only HA102 remains.
10.2 Three steps required. Accept two steps required if left-hand side of middle chosen for mid-
point on second step.
10.3 Eight steps required.
2 Programming
01 01.1 1 mark for each correct answer.
OUTPUT 'enter first number'
num1 ← USERINPUT
num2 ← USERINPUT
OUTPUT result
01.2 Any one of:
• num1 [1]
• num2 [1]
• result [1]
01.3 It is storing a value which is used elsewhere in the program that could change. [1]
237
age ← USERINPUT
IF age ≥ 18 THEN
ELSE
ENDIF
Selection ✓
Iteration ✓
number ← 5
OUTPUT number
number ← number – 1
ENDWHILE
238
radius ← USERINPUT
ENDWHILE
OUTPUT area
0 1 2 3
0 Lime Cherry Banana Pear
1 Lemon Orange Raspberry Damson
2 Strawberry Pineapple Plum
mins ← USERINPUT
ENDIF
09.2 Data validation is the process of checking data against pre-defined rules to ensure that it is
sensible and as expected. [1]
239
username ← ''
password ← ''
username ← USERINPUT
ENDWHILE
password ← USERINPUT
ENDWHILE
10.2 Authentication is used to confirm the identity [1] of someone using a computer system (to
ensure that they are who they say they are) and ensure that they should be granted access [1].
11 Any of the following ways up to a maximum of 4 marks:
• Lines 6, 8 and 10 should be indented [1] to clearly show what is happening in each part of the
if/else statement [1].
• The variable names m and n [1] should be changed to more meaningful names [1].
• Comments should be added [1] to explain the purpose of the if/else statements [1].
12 12.1 • Defines a function month [1] with number as a parameter [1].
• Includes a list of the months as names. [1]
• Uses the list to find the correct month name. [1]
• Returns the month name. [1]
Example:
SUBROUTINE month(number)
RETURN monthName
ENDSUBROUTINE
240
12.2 A temporary store of data [1] that is only available inside the module that it is defined in [1].
12.3 Allows reuse of code [1] without copying and pasting [1], improved maintainability [1] by
making code easy to read/follow [1] and shorter if called multiple times [1].
13 13.1 OUTPUT 'Enter the base'
base ← USERINPUT
height ← USERINPUT
OUTPUT area
13.2 • Define a function areaTriangle [1] that takes two parameters, base and height [1].
• Calculate the area of the triangle. [1]
• Return the area. [1]
SUBROUTINE trianglearea(base, height)
RETURN area
ENDSUBROUTINE
14 14.1 A logic error means that the program will run but will not give the expected output. [1]
14.2 IF number MOD i = 0 [1]
14.3 A syntax error is an error in the grammar of the program that will stop it from running. [1]
14.4 OUTPUT number + ' is a prime number' [1]
14.5 Iterative testing. [1]
15 15.1 1 mark for each correct answer:
Test data Test type Expected result
15 Normal Value accepted
0 (any value that is not an Invalid Invalid input message
integer between 1 and 20) displayed
1 (or 20) Boundary Value accepted
15.2 This type of testing ensures that only valid data is accepted, that the program works
correctly, and that the program is able to deal correctly with inappropriate entries. [1]
16 16.1 OUTPUT testScores[1][1] [1]
16.2 9 [1]
16.3 25 [1]
16.4 • Declare the variable total. [1]
• Use a loop to iterate through the values for the second index value. [1]
• Iterate through the values 0 to 4. [1]
• Calculate and output the average. [1]
241
Example program:
total ← 0
FOR i ← 0 TO 4
ENDFOR
average ← total / 5
OUTPUT average
17 17.1 Two of the following ways up to a maximum of 4 marks:
• Indentation [1] to show what is happening in each part of the if/else statement [1].
• Commenting [1] to explain what each part of the program is doing [1].
• Change variable from m [1] to something more meaningful such as mark [1].
17.2 1 mark for each correct answer:
Test data Test type Expected result
70 Valid ‘Grade B’
101 (Any integer less than 1 Invalid ‘Please enter your mark: ‘
or greater than 100)
81 or 100 Boundary ‘Grade A’
2 marks for correct answer: 1 mark for right hand 4 bits (0010), 1 mark for left hand 3 bits (111).
1 mark for showing correct working.
02 02.1 25 [1]
02.2 1100100 [1]
02.3 100 [1]
02.4 Multiplies the number by 4 [1]
02.5 The result is 1100 or 12 in decimal. We have lost the (LSB) / last 1 [1], causing loss of
precision [1]. This is in fact the same as performing integer division, i.e. 25 DIV 2.
242
243
4 Computer systems
01 01.1 AND (gate) [1]
01.2 Inverts / flips / switches an input and makes the output become the opposite of the input. [1]
01.3
A B C D E P
0 0 0 0 1 1
0 0 1 0 0 0
0 1 0 0 1 1
0 1 1 0 0 0
1 0 0 0 1 1
1 0 1 0 0 0
1 1 0 1 1 1
1 1 1 1 0 1
244
Security management
• Uses user accounts to control access to the computer system.
• Requires passwords to prove the identify of those accessing the system.
• Automatically updates the OS.
• Protects against malware.
02.2 Two of the following:
• Encryption software
• Defragmentation software
• Data compression software
• Backup software
02.3 Two of the following:
• Word processor
• Spreadsheet
• Web browser
• Database
• Media player
• Graphic design / CAD
03 03.1 Two of the following:
• A high-level language uses English-like keywords and syntax [1] which makes them easier
to read and write [1].
• High-level languages have to be translated into machine code in order to be executed. [1]
03.2 High-level code cannot be executed directly [1]. OR The program needs to be translated
into machine code in order to be executed by the processor [1].
03.3 • A compiler translates all of the code in one go [1]. It then produces an executable file
that can be saved and run again at any time [1].
• An interpreter translates and executes the code one line at a time [1]. When the program
is run again, each line of code has to be re-translated as no executable file is produced [1].
04 04.1 Two of the following:
• The code can be run directly by the processor.
• The code will execute very quickly.
• The system is likely to be low-powered so low-level languages will run more quickly.
04.2 Two of the following comparisons:
• High-level languages use English-like words and syntax [1]. Low-level languages use
binary or mnemonics [1].
• High-level languages can be run on a range of different types of computer [1].
Low-level languages are hardware dependent and can only run on one specific
type of computer [1].
• High-level languages abstract the details of the processor [1]. Low-level languages refer
directly to the computer’s hardware, so programmers need to understand how it works
[1].
• High-level languages need to be translated into machine code before they can be
run [1]. Low-level languages can be run directly by the processor [1].
245
246
(iii) T
he operating system, applications that are running and any associated data while the
computer is on and in use.
(iv) The instructions and data needed to get the system up and running and ready to load
the operating system from secondary storage.
07.2 (i) Because RAM is volatile, no data is stored in RAM once power is removed. We need
secondary storage to store various files on our computers so that they are available the
next time we switch on the computer.
(ii) Magnetic hard disk, solid state drive, optical disc, (hybrid disk) or equivalents/examples.
08 08.1 1 mark per bullet:
• dedicated function / special function …
• … built into another device.
08.2 1 mark for: (RAM might contain) user selections / current state / output messages/(i.e.
temporary data).
1 mark for: (ROM might contain) dedicated program / system settings.
08.3 Depends on the system described, but 2 marks per expanded bullet point to a maximum
of 4 marks for input, 2 marks for output:
Inputs
• Buttons to select program / enter time / select options.
• Sensors to detect system status / temperature / weight / water level / door open or
closed, etc.
• Remote connections to time signals / Wi-Fi or radio or nfc to remote devices or controls.
Outputs
• Displays to show time / selections / status, etc.
• Noises to signal errors /completion / confirmation of choices, etc.
08.4 1 mark per feature plus 2 marks for description (examples only – there are other
possibilities):
• Low power requirements [1]
o Battery operated. [1]
o Must work for a long time on one battery [1] …
o … to avoid the need to be removed frequently [1].
• Robust [1]
o Placed within body of a patient. [1]
o This is a harsh environment. [1]
• Small size [1]
o Placed via surgery. [1]
o Must be small enough to fit within the space available. [1]
247
03 03.1 Each computer or client is connected individually to a central point [1], usually a switch or
hub [1].
03.2 • A star topology is fast and reliable [1] as each device has its own connection to the
central node [1].
• Data is only directed to the intended device [1] which keeps network traffic to a minimum [1].
• It is easy to add new devices [1] as they simply need to be connected to the switch [1].
03.3 A white list can be created [1] so that only devices with known MAC addresses can be
allowed to connect to the network [1]. This prevents unauthorised users from gaining
access. / A black list can be used to deny access to any devices listed. [1]
03.4 1 mark per method and 1 mark per description, up to a maximum of 4 marks:
Firewall
• Monitors incoming and outgoing network traffic.
• Can block specific traffic based on pre-defined security rules.
Authentication
• Use of user names and passwords linked to user accounts to access the system.
Anti-malware
• To detect and prevent malicious software from entering the system.
248
04 04.1 1 mark for the topology and any of the following justifications up to a maximum of
2 marks:
• Star [1]
• Using wireless networking: Easy to set up [1] and no specialist knowledge required [1].
No wiring required [1] and devices can be moved around as necessary [1].
04.2 Any of the following up to a maximum of 3 marks:
• A school covers a reasonable area [1] and wiring a bus network would be extremely
complicated [1].
• A school will have many users [1]. A bus network would prove very slow because
collisions will require data to be sent repeatedly [1].
• In a bus network, one failed device causes the whole network to stop working [1] /
with a star, one failed device does not stop the network [1].
6 Cyber security
01 01.1 Any of the following up to a maximum of 4 marks:
• User access levels determine what software, hardware and files [1] different users are
allowed to access [1].
• They help to avoid attacks caused by the careless actions of users [1], for example,
preventing normal users from installing software which may contain malware [1].
• Confidential information can be limited to only those who need it [1], helping to protect
against insider attacks [1].
01.2 Testers take on the role of hackers to try to exploit weaknesses in the system [1]. Any
vulnerabilities can then be addressed [1].
02 02.1 • Memory sticks may be infected with malware [1]. When put into devices the malware
may be introduced to the network [1].
• Sensitive data may be written to the memory stick [1], allowing data to be stolen from
the organisation [1].
02.2 Any three of the following:
• Specify a minimum length for the password, usually at least eight characters. [1]
• Require both upper and lowercase letters. [1]
• Require the use of at least one number. [1]
• Require the use of at least one special character. [1]
02.3 Any two of the following:
• Use biometrics [1] to authenticate users [1].
• Ensure that software is automatically updated [1] to ensure that patches are applied
immediately [1].
• Use password systems where certain characters from a password have to entered [1] to
help prevent spyware from capturing password details.
03 03.1 Where someone is tricked/manipulated [1] into giving away information / access to a system [1].
03.2 The victim receives a fake email / SMS message [1] and responds by replying or clicking on
a link [1] allowing private information to be captured [1].
249
250
• Physical activity can be shared with friends and family to encourage participation in healthy
activities.
• Personal privacy compromised through tracking can identify when and where a person is/has
been and consequently leaves them open to criminal activity.
03 Discussion question. Marks based on the quality of the response. Areas that may be discussed
include:
• Dealing with a mix of driverless cars and human drivers, who are less predictable.
• Responsibility for any accident – the developer of the system or the owner of the vehicle?
• AI uses data about other vehicles – how is that data secured or used?
• Advantages of driverless cars when all/many cars are driverless – more efficient use of the
roads because they can communicate and cooperate.
• Driverless taxis would be efficient and inexpensive versus job losses.
04 Points may include:
• Control system for robotic limbs provide users with better and more precise control of the
limbs.
• Heart monitors and regulators to monitor heart conditions for diagnostic purposes; to alert
doctors to a problem; to apply a solution to a problem.
• Cochlear implant to provide a sense of sound to a person with profound hearing loss.
• Brain implant for partially sighted people transmits video images to the brain. Video images
from cameras attached to glasses bypass the eyes to restore some sight.
05 2 marks for advantage point plus expansion, 2 marks for disadvantage point plus expansion.
Points may include:
• Instant access to data from any location with internet access.
• Data stored away from the phone so backup secure and can restore a lost phone's data at
any time.
• Inexpensive backup compared to home computer, though home computer may not be an
additional cost.
251
D
engine management systems 154 arithmetic operators 37
ENIAC (Electronic Numerical Integrator arrays 42–4
data bus 145 and Computer) 138 Boolean operators 41
data collisions 174 entities 202 constants 30
data compression 117–18, 135 environmental impacts 213–14, 218–19 IF statements 32
lossless 104–9 erroneous test data 59, 71 inputs and outputs 46
lossy 103–4 error correction 60–1 random number generation 50
need for 103 ethernet 175, 185 relational operators 39
data inconsistency 200, 208 ethernet ports 172 string-handling operations 47
data packets 175 ethics 211–12, 218 subroutines 52–3
Data Protection Act 2018 212–13, 218 Euclidean algorithm 9 type conversion 48–9
data redundancy 200, 208 variables 29
data structures 65
arrays 42–4, 66
F WHILE and REPEAT UNTIL loops
35
records 45, 66 Fetch–Execute cycle 146–7, 161 Hopper, Grace 141
data theft 190 fibre-optic cables 172, 183 hubs 174
data types 26–8, 62 field names 45, 66 Huffman coding 105–7, 118
data validation 55–6, 70 fields 200 calculating bits required 108,
databases 200–1, 208 file size calculation 118–19
inserting, updating and deleting data image files 100, 116 Hypertext Transfer Protocol (HTTP) 177,
206–7, 209 sound files 102–3, 117 185
relational 201–2 File Transfer Protocol (FTP) 177, 185 Hypertext Transfer Protocol Secure
searches 203–5, 208–9 firewalls 180, 186 (HTTPS) 177, 185
decimal (denary) system 81, 111 flash memory 150–1
conversion to and from binary
83–5, 111–12
floating point numbers (real numbers) 27
flowchart symbols 4, 17 I
conversion to and from hexadecimal flowcharts 4–5, 16–17 identifiers 28, 62
86–7, 112–13 FOR EACH loops 43 IF statements 31–3, 63
decision boxes 4 FOR loops 33–4 image representation 115–16
declaration of variables 29, 62 use with arrays 42–3 colour 98–9
decomposition 2, 16 foreign keys 202, 208 file size 100
default passwords 189 fragmentation 150 pixels 97–8
definite (count-controlled) iteration functions 52, 54, 70 image size 97–8, 100, 116
33–4, 64 immoral behaviour 211
defragmentation 135
destructive testing 58
G impacts of digital technology 219
autonomous vehicles 217
device drivers 137 General Data Protection Regulation cloud storage 216
dictionary attacks 189 (GDPR) 212 computer-based implants 217
discrete values 100 gigabits 172 cyber security 215
DIV (integer division) 37 gigabytes (GB) 90, 114 hacking 216
dividing binary numbers 94, 114–15 greatest common divisor, algorithms for 9 mobile technologies 215
DNS servers 189 wearable technologies 216
domain names 189
driverless cars 217
H wireless networking 216
implants, computer-based 217
DVDs 151 hacking 216 inconsistent data 200, 208
hard disk drives (HDDs) 149–50, 162 increments 33
253
Internet 171 magnetic storage 149–50, 162, 163 OR gates 126, 157
internet layer, 4-layer TCP/IP model advantages and disadvantages 152 OR operator 40
178, 186 malicious code (malware) 189, 190, 193–4, output 3, 46, 67
Internet Message Access Protocol (IMAP) 196, 197–8 symbol for 4
177, 185 Media Access Control (MAC)
Internet Protocol (IP) 175, 185
interpreters 142–3, 160
address 180
megabits 172 P
inverters (NOT gates) 125 megabytes (MB) 90, 114 parameters 51, 69
IP addresses 175 memory 147–8, 161–2 passwords 57, 179, 189, 194, 196, 198
iteration 63–4 cache memory 145–6 storage 58
definite loops 33–4 RAM 148 patches 137, 190
indefinite loops 34–5 ROM 148 payloads 175
nested 36, 64 secondary storage 149–52 penetration testing 190–1, 197
memory management 137 peripherals 137
M Boolean 40–1
relational 38–9
binary search 14
bubble sort 11
MAC address filtering 180, 186 optical storage 151, 163, 164 linear search 13
machine code 138–9, 159 advantages and disadvantages 152 merge sort 12
254
R 177, 185
social engineering 189, 191–2, 196, 197
175, 185
transport layer, 4-layer TCP/IP model
random access memory (RAM) prevention 192 178, 186
148, 161–2 social media, privacy issues 214 Trojans 193, 198
random number generation 49–50, 68 software 124, 143, 156, 158, 160 truth tables 125, 156
read-only memory (ROM) 148, 162 application 136 for logic circuits 127–30
read/write memory 148, 162 systems 134–5 for logic gates 125–7
real data type 62 software updating 190, 195, 196, 198 Turing, Alan 195
real numbers (floating point numbers) 27 solid-state drives (SSDs) 150–1, 162–3 two-factor authentication 57, 70, 179, 194
records 45, 66, 200–1 solid-state storage 150, 162 type conversion (casting) 48–9, 67–8
redundant data 200, 208
U
advantages and disadvantages 152
registers 145, 160 sorting algorithms 9, 19–20
relational databases 201–2, 208 bubble sort 10–11
relational operators (comparison Unicode 96–7, 115
comparison of 12
operators) 38–9, 65 UNIVAC (Universal Automatic
merge sort 11–12
removable media, security threats Computer) 141
sound representation 117
190, 196 User Datagram Protocol (UDP) 175, 185
file size 102–3
REPEAT UNTIL loops 34–5, 64 usernames 57, 179
sampling and digital storage 100–2
reserved keywords 28 utility software 134
spyware 194, 198
V
resolution star network topology 174, 183–4
images 98 string conversion 48–9, 67–8
sound files 102 string data 62 variables 28–30, 62
robust programs 55, 70 string-handling operations 46–9, 67–8 local 53, 69
run-length encoding (RLE) 108–9, 119 concatenation 47–8 VB.Net 6
S
strings 27–8 FOR loops 34
structured programming 68–70 arithmetic operators 37
advantages 53–4 arrays 43–4
sample rate 102, 117
subroutines 50–3 Boolean operators 41
sample resolution 102, 117
Structured Query Language (SQL) 203–4, IF statements 32
sampling sound signals 101, 117
208–9 inputs and outputs 46
searches, Structured Query Language
inserting, updating and deleting data random number generation 50
(SQL) 203–7, 208–9
206–7 relational operators 38–9
searching algorithms 9, 21
using multiple tables 204–5 string-handling operations 47
binary search 13–14
subroutines 50, 68–9 subroutines 52
comparison of 15
defining 51 type conversion 48
linear search 13
local variables 53 variables 29
secondary storage 149, 162–4
passing parameters 51–2 WHILE and REPEAT UNTIL loops 35
cloud storage 152
returning values 52–3 viruses 193, 198
magnetic 149–50
symbol for 4 volatile and non-volatile memory 148, 162
optical 151
switches 174 Von Neumann architecture 144, 160
solid-state 150–1
255
W X
wide area networks (WANs) 171, 182
Wi-Fi 175, 185
waste disposal 213–14 wildcards 203 XOR gates 127, 157
wearable technologies 216 wired networks 172, 173, 183 XOR and AND gates 129–30
WHILE loops 34–5, 64 wireless access points (WAPs) 173, 183
white-box penetration tests wireless LANs 175
191, 197 wireless networks 173, 183
white lists 180 impact of 216
256
Photo credits
p. 2 © Tovovan/stock.adobe.com; pp. 99, 104 all © George Rouse; p. 124 © Wellcome Collection. Attribution 4.0 International
(CC BY 4.0); p. 138 © Bettmann/Corbis via Getty Images; p. 141 © Division of Medicine and Science, National Museum of
American History, Smithsonian Institution; p. 144 © Ymgerman/Shutterstock.com; p. 149 © mingis/istock/thinkstock; p. 150
© Gianni Furlan/Hemera/thinkstock; p. 151 © sergojpg /stock.adobe.com; p. 153 © Sergey Jarochkin/123RF; p. 154 © samunella/
stock.adobe.com; p. 214 © Peter Essick/Aurora Photos/Cavan/Alamy Stock Photo.
Every effort has been made to trace all copyright holders, but if any have been inadvertently overlooked the Publishers will be
pleased to make the necessary arrangements at the first opportunity.
257
Please note, none of Visit our website or contact your local Sales Representative to find out
the Code-IT in Python more about Code-IT in Python and to register for a free trial.
modules are approved
by AQA. www.hodderducation.co.uk/code-it [email protected]