100% found this document useful (1 vote)
682 views

Essential Maths Skills For ASA Level Computer Science Nodrm

Uploaded by

nikeks23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
682 views

Essential Maths Skills For ASA Level Computer Science Nodrm

Uploaded by

nikeks23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 105

Essential Maths Skills

for AS/A-level

Computer
Science
Gavin Craddock and Victoria Ellis
Philip Allan, an imprint of Hodder Education, an Hachette UK company, Blenheim Court, George Street,
Banbury, Oxfordshire OX16 5BH
Orders
Bookpoint Ltd, 130 Park Drive, Milton Park, Abingdon, Oxfordshire OX14 4SE
tel: 01235 827827
fax: 01235 400401
e-mail: [email protected]
Lines are open 9.00 a.m.–5.00 p.m., Monday to Saturday, with a 24-hour message answering service. You
can also order through the Hodder Education website: www.hoddereducation.co.uk
© Gavin Craddock and Victoria Ellis 2016
ISBN 978-1-4718-6357-8
First printed 2016
Impression number 5 4 3 2 1
Year 2020 2019 2018 2017 2016
All rights reserved; no part of this publication may be reproduced, stored in a retrieval system, or
transmitted, in any other form or by any means, electronic, mechanical, photocopying, recording or
otherwise without either the prior written permission of Hodder Education or a licence permitting restricted
copying in the United Kingdom issued by the Copyright Licensing Agency Ltd, Saffron House, 6–10 Kirby
Street, London EC1N 8TS.
Typeset in India
Cover illustration: Barking Dog Art
Printed in Spain
Hachette UK’s policy is to use papers that are natural, renewable and recyclable products and made from
wood grown in sustainable forests. The logging and manufacturing processes are expected to conform to
the environmental regulations of the country of origin.
Contents
The content listed in bold is only specified to be assessed by AQA and is not assessed by
OCR, WJEC or Eduqas.

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

1 Number systems and sets


Number systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

2 Number bases
Converting a base 2 or base 16 number to base 10 . . . . . . . . . . . . . . . . . . . . . .14
Converting a base 10 to a base 2 or base 16 number . . . . . . . . . . . . . . . . . . .16

3 Units
Binary prefixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Decimal prefixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

4 Arithmetic operations in a programming


language
DIV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Mod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Power . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Rounding and truncating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Logical operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

5 Binary numbers
Signed vs unsigned binary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Key values for n bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Binary addition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Binary multiplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Representing negative numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Fixed point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Logical shifts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Bitwise operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
6 Floating point data representation
Floating point binary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Normalisation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

Range and precision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63


Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

7 Representing images, sound and other


data
Bitmap images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Sound samples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

8 Boolean algebra
Logic gates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Boolean algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .76

Boolean identities and De Morgan’s laws . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78

9 Vectors
Vector representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Vector addition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Scalar vector multiplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Dot product of two vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Convex combination of two vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

10 Big-O notation and complexity of algorithms


Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Complexity of algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

Exam-style questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

Appendix
Specification cross–reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103

Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


Introduction

The new A-levels in computer science have incorporated mathematical skills that form
the fundamentals of computing. Computers cannot function without mathematics. Even
the basics, such as the storage of data, rely on the use of binary numbers. Creating images
relies on vectors, and writing algorithms involves mathematical functions.
This book is intended to help anyone who is struggling with the mathematics skills
involved, or who would like to consolidate or revise the key skills. It is not specific to
one examination board, but instead covers all of the different topics that each syllabus
requires. Take a look at the cross-reference chart (page 103) to check what is needed for
the specification you are studying. Likewise, particular topics that are relevant to only
one examination board are also indicated in the table of contents.
Each skill is broken down into a series of easy-to-follow steps, with worked examples
to walk you through the application of these skills. There is then a series of guided
questions, where some or all of the instructions are given, asking you to complete the
actions and fill in any gaps to reach the solution. Finally, there are practice questions for
you to work through on your own.
We hope that this book will give you more confidence with the mathematical concepts of
computer science and support you in your studies. Good luck!
Full worked solutions to the guided and practice questions and exam-style questions can
be found online at www.hoddereducation.co.uk/essentialmathsanswers.

Introduction 5
This page intentionally left blank
1 Number systems and sets

Before investigating how computers represent numbers, it is important to understand the


fundamental number systems that are used in mathematics. Each of these has its own
properties and reasons why it is useful to computer scientists.

Number systems
Natural numbers
Natural numbers are positive whole numbers, including 0. The symbol ℕ is used for the
set of natural numbers, so that ℕ = {0, 1, 2, 3, …}
The natural numbers are used for counting (such as ‘there are 17 students in this
class’) and ordering (such as ‘the team finished in 3rd place’). In computer science, it
is important to remember that, if a member of ℕ is added to or multiplied by another
member of ℕ, the result is also a member of ℕ. This allows natural numbers to be used as
counters in computer programs.

Integers
Integers are negative and positive whole numbers, again including 0. The symbol ℤ is
used for the set of integers, so that ℤ = {…, –3, –2, –1, 0, 1, 2, 3, …}. ℤ is used for integers
because ‘Zahlen’ is German for ‘numbers’.
Just as with natural numbers, if a member of ℤ is added to or multiplied by another
member of ℤ, the result is also a member of ℤ. This is also true for subtraction as ℤ
includes the negative whole numbers. Integers are therefore very useful as counters in
computer programs for whole quantities that may be negative.

Rational numbers
Rational numbers are those numbers that can be written as a fraction, such as 7 or 3 .
5 2
The symbol ℚ is used for the set of rational numbers and can be thought of as standing
for ‘quotient’ to aid remembering.
x
A rational number can be defined as a number in the form , where x and y are both members
y
9
of ℤ and y is not zero. Since a number such as 9 can be written as the fraction , ℚ includes
1
all members of ℤ. When any rational number is written as a decimal, it either terminates after
1 1
a finite number of digits (such as = 0.125) or recurs (such as = 0.333333333…).
8 3

Irrational numbers
Irrational numbers are those numbers which are not rational: that is, they cannot be
written as a fraction. Famous examples of irrational numbers include π, e and 2 .

1 Number systems and sets 7


The decimal version of any irrational number neither terminates nor recurs. For example,
1 Number systems and sets

π can be written as 3.141592… but this series of digits will continue infinitely. The world
record for the number of digits calculated for π currently stands (as of 2015) at 2.7 trillion
digits. For this reason, any computer representation of an irrational number will actually
be a very close approximation.

Real numbers
Real numbers are the set of all possible real world quantities. Another way of thinking
about real numbers is that they are the points on an infinitely long line. Every possible
value, both positive and negative, appears somewhere on the line. The symbol ℝ is used
for this set. ℝ contains all natural numbers (ℕ), integers (ℤ), rational numbers (ℚ) and
irrational numbers.
Real numbers are very useful for measuring. For example, if three people ran a race, their
times (in seconds) may be 15, 17.3 and 18.3454. These are all real numbers.

A Worked examples
a For each of the following, explain which set(s) of numbers they belong to (either natural,
integer, rational, irrational or real). A number may be a member of more than one set.
i 35
■ Because this is a whole number (with no decimal places), this is a natural number and also
an integer.
35
■ Because it can be written in the form , it is also a rational number.
1
■ Finally, it is also a real number.
ii 12.5
■ The decimal point means that this is definitely not a natural number or an integer.
■ It can be written in the form 25 , so is therefore a rational number.
2
■ In addition, it is also a real number.
iii 3
■ In decimal form, this is 1.4142135… It does not terminate or recur, therefore it is an irrational
number.
■ Just like every other number, it is also a real number.
b Decide whether each of the following statements is true or false.
i All natural numbers are also integers.
This is TRUE. The set of integers includes all natural numbers AND also includes negative
numbers.
ii A square root is always irrational.
This is FALSE. Most roots (such as 2 or 3 ) are irrational. However, 4 = 2 and 9 = 3.
These are certainly not irrational!
iii A number is either rational or irrational, but never both.
This is TRUE. The definitions of these number sets are opposites: if a number is rational then it
cannot be irrational and vice versa.

8 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


B Guided questions

1 Number systems and sets


Copy out the workings and complete the answers on a separate piece of paper.
1 For each of the following, explain which set(s) of numbers it belongs to (either
natural, integer, rational, irrational or real). A number may be a member of
more than one set.
a 17.125
b 13
c –6
d 3.14
For each part of question 1, follow these steps:
Step 1: does the number include a decimal place? If so, it cannot be a natural number
or an integer. Go to Step 4.
Step 2: if it doesn’t include a decimal place, is it negative? If it is negative, it is an
integer. If not, it is both an integer and a natural number.
Step 3: all integers and natural numbers can be written as a fraction (with 1 as the
denominator) so the number is also a rational number. Go to Step 5.
Step 4: can the number be written as a fraction? In order to do this, the number must
either terminate (such as 1.35) or recur (such as 9.666666666). If it can be written as a
fraction, it is a rational number. If not, it is an irrational number.
Step 5: all numbers are also real numbers.
2 Given that x = 2, y = 5 and z = 3, calculate the value of (2x + z) – (y × x) and state
which number set(s) it belongs to.
Step 1: replace the values of x, y and z in the expression.
Step 2: calculate the value of each pair of brackets.
Step 3: carry out the subtraction.
Step 4: using the rules from question 1, decide which number set(s) the answer
belongs to.

C Practice questions
3 For each of the following, state which number set(s) it belongs to (either natural,
integer, rational, irrational or real). A number may be a member of more than one set.

a (4 + 4)

b 4 + 4

c 17 – (10 + 9)
16
d
3

1 Number systems and sets 9


4 Decide whether each of the following statements is true or false.
1 Number systems and sets

a All integers are also rational numbers.


b All rational numbers are also integers.
c 0 is not a natural number.
5 Given that a = 1, b = 7 and c = 12, calculate the value of each of the following and
state which number set(s) it belongs to.
a (a + b) – c
b+c
b
c
c π+a

Sets
Note: this topic is assessed at A-level by AQA only.

Notation for sets


In the previous section, sets have been discussed without explicitly discussing what one
is. A set is an unordered collection of values in which each value occurs at most once.
Curly braces { } are used to define a set, such as A = {5, 6, 7, 8, 9}. An empty set (one
with no elements) can either be shown using { } or using the symbol Ø.
Table 1.1 shows other symbols that are used for set comprehension.

Table 1.1

Symbol Explanation
… An ellipsis is used to show a regular sequence. {1, 2, 3, …, 100} is the set of all
natural numbers between 1 and 100. The ellipsis shows that all numbers in between
3 and 100 are also included.
| ‘Such that’. This is used as a separator with the variable to the left and the rule to
the right.
∈ ‘is a member of’. x ∈ ℕ means that x is a member of the set of natural numbers.
∧ ‘AND’. x > 7 ∧ x < 10 means x is greater than 7 and x is less than 10.

For example, A = {x | x ∈ ℕ ∧ x < 6} would be read as ‘x, such that x is a member of


the set of natural numbers and x is less than 6’. In this example, A = {0, 1, 2, 3, 4, 5}.
If needed, the variable to the left of the separator can be replaced by a term (such as 2x,
or 2x + 1). If B = {2x | x ∈ ℕ} then B is {0, 2, 4, 6,…}, the set of all even natural numbers.
If C = {2x + 1 | x ∈ ℕ ∧ x < 4} then C is {1, 3, 5, 7}, the set of all odd natural numbers
2x + 1, where x < 4.

10 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


Finite and infinite sets

1 Number systems and sets


A finite set is one with a finite number of elements. For example, {1, 2, 7, 10} is a finite
set as it has four elements. An infinite set is one that has an infinite number of elements
such as ℝ, the set of real numbers. It is impossible to count how many real numbers
there are.
A countably infinite set is one that can be counted off by the natural numbers. Rational
numbers are countably infinite in this way. However, German mathematician Georg
Cantor proved that real numbers are not countable.

Subsets
A subset is defined as a set that is wholly contained within another set. For example,
if A = {1, 2, 3, 4} and B = {2, 3} then B is a subset of A. The symbol ⊆ is used
to mean subset, so B ⊆ A reads ‘B is a subset of A’. The line in this symbol is
reminiscent of an equals sign because a subset can technically have exactly the same
elements as the superset. That is, if D = {1, 2, 3, 4} and E = {1, 2, 3, 4}, D = E and
D ⊆ E are both true.
A proper subset uses the symbol ⊂ and is defined as a subset where at least one element
is in the superset that is not in the subset. For example, {1, 2, 3} is a proper subset of ℕ
because there is at least one element in ℕ that is not in {1, 2, 3}.

Set operations
The main operations that can be carried out on sets are union, intersection, difference
and Cartesian product.
■ The union of sets A and B is the set of all elements that are a member of either or
both sets. The symbol ∪ is used to show union. If A = {1, 3, 7, 9} and B = {1, 2, 4, 7}
then A ∪ B = {1, 2, 3, 4, 7, 9}.
■ The intersection of sets A and B is the set of all elements that are members of both
sets. The symbol ∩ is used to show intersection. Using the same sets for A and B
above then A ∩ B = {1, 7}.
■ The difference of sets A and B is the set of all elements that are members of A but not
members of B. The symbol \ is used to show difference. Again using the same sets as
above, A \ B = {3, 9}.
■ The Cartesian product of two sets is the set of all possible ordered pairs between the
two sets. The symbol × (the same symbol that is used for multiplication) is used to
denote a cartesian product. For example, if A = {1, 7} and B = {True, False} then
A × B = {(1, True), (1, False), (7, True), (7, False)}.

1 Number systems and sets 11


A Worked examples
1 Number systems and sets

a Find A, where A = {x | x ∈ ℤ ∧ x > –3}.


Step 1: understand the set comprehension statement. This is asking for all of the values of x, such
that x is a member of the set of integers AND x is larger than –3.
Step 2: integers are negative and positive whole numbers. Therefore integers larger than –3 are
–2, –1, 0, 1, 2, 3, 4 and so on. This set continues infinitely upwards.
Step 3: as the set shows a regular sequence, use the … notation to show that the values continue.
Therefore, A = {–2, –1, 0, 1, 2, 3, …}
b If A = {7, 8, 9, 10} and B = {5, 6, 7, 8}, find:

i A B
The union of two sets includes the elements that are members of either set (or both). Be careful
not to repeat any elements. It may be helpful to think of this as joining the sets together and
removing any duplicates. A ∪ B = {5, 6, 7, 8, 9, 10}

ii A∩B
The intersection of two sets includes the elements that are members of both sets. A ∩ B = {7, 8}

iii A \ B
The difference of two sets is simply the elements that are in the first which are not in the second.
A \ B = {9, 10}

B Guided questions
Copy out the workings and complete the answers on a separate piece of paper.
1 Find A where A = {x | x ∈ ℕ ∧ x > 4 ∧ x < 10}.
Step 1: understand the set comprehension statement. This is asking for all of the
values of x, such that x is a member of the set of natural numbers AND x is larger
than 4 AND x is smaller than 10.
Step 2: write the distinct values that meet all of these criteria between {curly braces}.
2 Find A where A = {3x – 1 | x ∈ ℕ ∧ x > 5}.
Step 1: find all values of x that are members of the set of natural numbers AND larger
than 5.
Step 2: when you have these values, use the equation 3x – 1 to find the elements of
the set A.
Step 3: write the values that you obtained in Step 2 between {curly braces}. If the
values continue in a regular sequence, use the ellipsis (…) to show this.
3 If A = {7, 9, 12} and B = {9, 12, 15}, find A ∪ B.
Step 1: decide the appropriate operation for the symbol ∪.
Step 2: compare both sets using the operation from Step 1 and list all the elements.

12 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


4 If A = {2, 4, 6, 8}, B = {2, 3, 4, 5} and C = {x | x ∈ (A ∩ B) ∧ x < 4}, find C.

1 Number systems and sets


Step 1: understand the set comprehension statement. This involves first working out
the elements of A ∩ B.
Step 2: the use of ∧ for ‘AND’ means that there is a second criterion.
Step 3: list all elements that meet both of these criteria.

C Practice question
5 If A = {1, 2, 3, 4, 5, 6}, B = {2, 4, 6, 8} and C = {6, 7, 8, 9}, find:
a B∩C

b C\B

c (A ∩ B ) ∪ C

d (C ∩ B) \ A

e {x | x ∈ B ∧ x >3}

f {x| x ∈ A ∧ x > 2 ∧ x < 6}

g {2x | x ∈ C }

f {x2 | x ∈ (A ∪ C) ∧ x < 8}

1 Number systems and sets 13


2 Number bases

‘Number base’ means the number of different symbols that are used. So if you have base
10 (known as decimal, or denary), there are 10 different symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
These symbols are then combined to represent any number, e.g. 12, 99, 386.
Binary is base 2 and there are two different symbols: 0 and 1.
Hexadecimal is base 16 and there are 16 different symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B,
C, D, E, F. Letters are used in hexadecimal instead of two-digit numbers.

A = 10 C = 12 E = 14
B = 11 D = 13 F = 15

The base of a number can be identified by its subscript:


■ If the subscript is 10, e.g. 910, this means it is a base 10 number (decimal).
■ If the subscript is 2, e.g. 10112, this means it is a base 2 number (binary).
■ If the subscript is 16, e.g. 28116, this means it is a base 16 number (hexadecimal).

Converting a base 2 or
base 16 number to base 10
Each digit in a number can be converted into its decimal (base 10) value using four
steps as shown in the Worked examples that follow. Table 2.1 shows how the digits are
presented in table format. In computer science we start counting at 0. The first digit (on
the right) is Digit 0 (D0). This is multiplied by its base to the power of 0 (base0). Digit 1
(D1) is multiplied by its base to the power of 1 (base1). Digit 2 (D2) is multiplied by its
base to the power of 2 (base2) and so on.

Table 2.1

D4 D3 D2 D1 D0
× base 4
× base 3
× base 2
× base 1
× base0

Multiplying to the power of 2 means the number multiplied by itself, i.e. 42 = 4 × 4.

Multiplying to the power of 3 means the number multiplied by itself, multiplied by


itself, i.e. 43 = 4 × 4 × 4.

14 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


Worked examples

2 Number bases
A
a Convert the binary number 0101 to decimal.
Step 1: put the binary number into the table format as shown in Table 2.1.

0 1 0 1
× base3 × base2 × base1 × base0

Step 2: binary is base 2, so replace the word ‘base’ with 2.

0 1 0 1
× 23 × 22 × 21 × 20

Step 3: calculate each column.

0 × 23 = 0 1 × 22 = 4 0 × 21 = 0 1 × 20 = 1

Step 4: add the columns together.


0+4+0+1=5
b Convert the hexadecimal number 1D9 to decimal.
Step 1: put the hexadecimal number into the table format as shown in Table 2.1.

1 D 9
× base2 × base1 × base0

Step 2: hexadecimal is base 16, so replace the word ‘base’ with 16.

1 D 9
× 162 × 161 × 160

Step 3: calculate each column, replacing any letters with their numerical equivalent. (D = 13; see box
on previous page.)

1 × 162 = 256 13 × 161 = 208 9 × 160 = 9

Step 4: add the columns together.


256 + 208 + 9 = 473

2 Number bases 15
B Guided questions
2 Number bases

Copy out the workings and complete the answers on a separate piece of paper.
1 Convert the binary number 11100 to denary. Show your working.
Steps 1 and 2: put the number into table format and fill in the number base for binary
in each column. One has been done for you.

1 1 1 0 0
× 24 × 3
× 2
× 1
× 0

Steps 3 and 4: complete the calculation for each column and add the columns. Again,
one has been done for you.
16 + + + +
The answer is .
2 Convert the hexadecimal number 3F to denary. Show your working.
Steps 1 and 2: put the number in table format and fill in the second hexadecimal
number on the top row and the bases on the bottom row.

3
1 0
× ×

Steps 3 and 4: complete the calculation for each column and add the columns.
+

The answer is .

C Practice questions
3 Convert the binary number 1011 to decimal.
4 Convert the hexadecimal number 29 to decimal.
5 Convert the binary number 10111 to decimal.
6 Convert the hexadecimal number AB to decimal.
7 Convert the binary number 10110110 to decimal.
8 Convert the hexadecimal number 32F1 to decimal.

Converting a base 10 to a
base 2 or base 16 number
Using division, you can convert a base 10 (decimal) to both base 2 (binary) and base
16 (hexadecimal).

16 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


A Worked examples

2 Number bases
a Convert 2910 to base 2 (binary).
■ Divide the number by the base you want it in until you get 0.
■ You want base 2 so you divide by 2.
Step 1: divide the number by 2.
29 ÷ 2 = 14 r 1
Step 2: take the quotient (the result) and divide it by 2.
14 ÷ 2 = 7 r 0
Step 3: repeat this process until you have 0 — quotient divided by 2.
7÷2=3r1
Still not 0? Repeat — quotient divided by 2.
3÷2=1r1
Still not 0? Repeat — quotient divided by 2.
1÷2=0r1
Make sure you write your remainder, as this will be used to make the answer.
Step 4: now you have 0, write all the remainders from the last to the first; 11101.
b Convert 10010 to binary (base 2).
Step 1: divide 100 by 2.
100 ÷ 2 = 50 r 0
Step 2: divide the quotient by 2.
50 ÷ 2 = 25 r 0
Step 3: repeat until you have 0.
25 ÷ 2 = 12 r 1
12 ÷ 2 = 6 r 0
6÷2=3r0
3÷2=1r1
1÷2=0r1
Continue dividing by 2 until you have 0.
Step 4: write all the remainders, from the last to the first, 1100100.
c Convert 2910 to base 16 (hexadecimal).
Step 1: divide the number by 16.
29 ÷ 16 = 1 r 13
Step 2: divide the quotient by 16.
1 ÷ 16 = 0 r 1

2 Number bases 17
Step 3: repeat until you have 0.
2 Number bases

Step 4: write the remainders, from the last to first; 1 13.


Step 5: check for numbers over 9. You can’t use the
A = 10 C = 12 E = 14
number 13 in hexadecimal. You need to replace it with
the appropriate letter, D B = 11 D = 13 F = 15

1 13 becomes 1D
d Convert 10010 to hexadecimal (base 16).
Step 1: divide the number by 16.
100 ÷ 16 = 6 r 4
Step 2: divide the quotient by 16.
6 ÷ 16 = 0 r 6
Step 3: repeat until you have 0.
Step 4: write the remainders, from last to first, 64.
Step 5: check for numbers over 9. There are none.

B Guided questions
Copy out the workings and complete the answers on a separate piece of paper.
1 Convert 6110 to binary (base 2).
Step 1: divide the number by 2. 61 ÷ 2 = 30 r 1
Step 2: divide the quotient by 2. 30 ÷ 2 = 15 r
Step 3: repeat until you have 0. 15 ÷ 2 = r
÷2= r
÷2= r
÷2= r
Step 4: write the remainders from last to first.
2 Convert 15610 to binary.
Step 1: divide the number by 2. 156 ÷ 2 = r
Step 2: divide the quotient by 2. ÷2= r
Step 3: repeat until you have 0. ÷2= r
÷2= r
÷ = r
÷ = r
÷ = r
÷ = r
Step 4: write the remainders from last to first.

18 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


3 Convert 5710 to hexadecimal (base 16).

2 Number bases
Step 1: divide the number by 16. 57 ÷ 16 = 3 r
Step 2: divide the quotient by 16. 3 ÷ 16 = r
Step 3: repeat until you have 0.
Step 4: write the remainders from last to
A = 10 C = 12 E = 14
first, replacing any 2-digit numbers with
their letter. B = 11 D = 13 F = 15

4 Convert 18710 to hexadecimal.


Step 1: divide the number by 16. 187 ÷ 16 = r
Step 2: divide the quotient by 16. 11 ÷ = r
Step 3: repeat until you have 0.
Step 4: write the remainders from last to A = 10 C = 12 E = 14
first, replacing any 2-digit numbers with
B = 11 D = 13 F = 15
their letter.

C Practice questions
5 Convert 2510 to binary.
6 Convert 16110 to binary.
7 Convert 24510 to binary.
8 Convert 3810 to hexadecimal.
9 Convert 11710 to hexadecimal.
10 Convert 23310 to hexadecimal.

2 Number bases 19
3 Units

Note: this Unit is assessed at AS and A-level by AQA only.


Different quantities of bits can be described with specific names and prefixes. You should
know quite a few of these terms, but you also need to know what they represent.
■ At the very basic level you have bits, nibbles and bytes.
■ A bit is just 1 binary digit, e.g. 1 or 0.
■ A nibble is 4 bits, e.g. 0110 or 1101.
■ A byte is 8 bits (or 2 nibbles), e.g. 10101101 or 01011011.

Binary prefixes
After a byte you start recording the number of bits in powers of 10.
Table 3.1

Number Binary prefix Stands for


210 Ki Kibi

220 Mi Mebi
230 Gi Gibi
240 Ti Tebi

These are called prefixes because they will all come before what they represent, which is
the number of bytes:
■ Kibibyte = 210 bytes = 1024 bytes
■ Mebibyte = 220 bytes = 1 048 576 bytes
■ Gibibyte = 230 bytes = 1 073 741 824 bytes
■ Tebibyte = 240 bytes = 1 099 511 627 766 bytes

Decimal prefixes
These work in the same way. However, for a decimal number, these increase by a power
of 3 each time.
Table 3.2

Number Decimal prefix Stands for Number


103 k Kilo 1 000
106 M Mega 1 000 000
109 G Giga 1 000 000 000
1012 T Tera 1 000 000 000 000

The decimal prefixes are the ones most commonly known and used in computing,
e.g. a kilobyte (kB) is 1000 bytes, whereas a kibibyte (KiB) is 1024 bytes.

20 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


CONVERTING BETWEEN VALUES

3 Units
You may be asked, for example, how many Mi are in a Ti. You don’t need to learn all
of the different numbers, just remember the patterns and the rule for dividing
40
numbers with powers: Ti = 2 = 240–20
Mi 220

A Worked examples
a How many MiB are in a TiB?
Step 1: write down the values for each.
MiB = 220 TiB = 240
Step 2: work out the difference in powers. Subtract the smaller power (20) from the larger power (40)
to get the new power. 40 – 20 = 20
The answer is 2 to the power of the difference in powers, 20. 220 = 1 048 576
b How many MB are in 2 GB?
Step 1: write down the values for each.
MB = 106 GB = 109
Step 2: work out the difference in powers.
9 – 6 = 3, so 23 = 1000
Step 3: you need 2 GB, so multiply by 2.
1000 × 2 = 2000
You can give the answer in terms of 103, so 2 × 103 would also be acceptable for the answer.

B Guided questions
Copy out the workings and complete the answers on a separate piece of paper.
1 How many kB are in a GB?
Step 1: write down the values for each.
kB = 103 GB = 109
 tep2:workoutthedifferenceinpowers.Writethevalueforthelargerpower−the
S
smaller power.
2 How many MiB are in 4 TiB?
Step 1: write down the values for each.
Step 2: work out the difference in powers.
Step 3: there are 4 TiB, so multiply by 4.

C Practice questions
3 How many kB are in 8 MB? 6 How many GiB are in 5 TiB?
4 How many KiB are in 10 TiB? 7 How many MB are in 12 GB?
5 How many GB are in 3 TB?

3 Units 21
4 Arithmetic operations in a
programming language

When you write in a programming language, it is likely that you will need to perform
calculations. Programming languages have symbols that may vary slightly between
languages, but perform the same functions.

Table 4.1
Symbol Name Function Example
x+y Addition Add two numbers together 2+3=5
x–y Subtraction Take one number away from another 5–2=3
x*y Multiplication Multiply x by y 2*4=8
x/y Division Divide x by y 10/2 = 5
13/2 = 6.5
x MOD y Modulus Find the remainder of the division xy 13 MOD 2 = 1
100 MOD 12 = 4
x DIV y Integer division / Find the integer (whole number) part of the 13 DIV 2 = 6
quotient division xy 100 DIV 12 = 8

x^y Power Find x to the power of y (xy) 10^2 = 100


4^3 = 64

This Unit will not look at the basic operations of +, –, * or /, but the operations MOD,
DIV and ^.

DIV
DIV gives the whole, integer, value of the division. In other words, the number before the
decimal point.

A Worked examples
a What is 10 DIV 2?
Step 1: divide the numbers.
10
=5
2
Step 2: the answer is the number before the decimal point, 5.
b What is 15 DIV 9?
15
Step 1: = 1.666
9
Step 2: answer = 1

22 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


B Guided questions

4 Arithmetic operations in a programming language


Copy out the workings and complete the answers on a separate piece of paper.
1 What is 20 DIV 7?
20
Step 1:
7
Step 2: write the number(s) before the decimal point.
2 What is 104 DIV 5?
Step 1: divide the numbers.
Step 2: write the number(s) before the decimal point.

C Practice questions
3 What is 38 DIV 7?
4 What is 49 DIV 2?
5 What is 100 DIV 3?
6 What is 166 DIV 12?
7 What is 215 DIV 156?

Mod
The modulus works out the number left over after the quotient division, for example,
13 DIV 2 = 6 with 1 left over (2 × 6 = 12), so 13 MOD 2 = 1. Another way of working it
out is using the quotient division, for example:
Step 1: work out the division.
13
= 6.5
2
Step 2: multiply the quotient (6), by the number you divided by (2).
6 × 2 = 12
Step 3: subtract this (12) from the first number (13), giving 1.

A Worked examples
a What is 27 MOD 6?
In computing, the quotient
Step 1: work out the division.
is the part before the
27
= 4.5 decimal point. In 4.5 it is 4.
6
Step 2: multiply the quotient (4) by the number you divided by (6).
4 × 6 = 24
Step 3: subtract this from the first number to get the answer.
27 – 24 = 3

4 Arithmetic operations in a programming language 23


b What is 88 MOD 5?
4 Arithmetic operations in a programming language

Step 1: work out the division.


88
= 17.6
5
Step 2: multiply the quotient (17) by the number you divided by (5).
17 × 5 = 85
Step 3: subtract this from the first number to get the answer.
88 – 85 = 3

B Guided questions
Copy out the workings and complete the answers on a separate piece of paper.
1 What is 50 MOD 8?
Step 1: work out the division.
50
= 6.25
8
Step 2: multiply the quotient (6) by the number you divided by (8).
Step 3: subtract this from the first number (50) to get the answer.
2 What is 1 MOD 4?
Step 1: work out the division.
1
= 0.25
4
Step 2: multiply the quotient (0) by the number you divided by (4).
Step 3: subtract this from the first number (1) to get the answer.

C Practice questions
3 What is 12 MOD 3?
4 What is 51 MOD 9?
5 What is 4 MOD 9?
6 What is 20 MOD 10?
7 What is 102 MOD 6?

Power
The ^ is the symbol for ‘to the power of’. Instead of writing 210, in programming you
would enter 2^10.

24 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


A Worked examples

4 Arithmetic operations in a programming language


a What is 3^6?
■ Turn into multiplication.
■ Multiply the first number (3) by itself by writing it down the second number of times (6)
3 × 3 × 3 × 3 × 3 × 3 = 729
b What is 4^5?
■ Turn into multiplication.
■ Multiply the first number (4) by itself by writing it down the second number of times (5).
4 × 4 × 4 × 4 × 4 = 1024

B Guided questions
Copy out the workings and complete the answers on a separate piece of paper.
1 What is 5^3?
Multiply the first number (5) by itself by writing it down the second number of times (3).
2 What is 8^4?
Multiply the first number (8) by itself by writing it down the second number of times (4).

C Practice questions
3 What is 3^5?
4 What is 10^3?
5 What is 12^2?
6 What is 4^7?
7 What is 5^5?
8 What is 20^3?

Rounding and truncating


Rounding involves making a number less precise, but easier to represent. For example,
by reducing the number of decimal places, you will lose the final number, e.g. 2.543
may become 2.54, so the 3 is lost. This means it is less precise, but it is easier to
represent (and in some cases understand, especially if the number does not need to be
that exact).
Rounding can be used within programming. Each language has its own function to
perform this task. When writing the function, you will need to state how many decimal
places you want to be displayed.
Depending on the language you use, there may be up to three different rounding
functions:

4 Arithmetic operations in a programming language 25


1 roundUp(number, no. of decimal places) — this always rounds up, no matter what the
4 Arithmetic operations in a programming language

next number is
2 roundDown(number, no. of decimal places) — this always rounds down, no matter
what the next number is
3 round(number, no. of decimal places) — this will round down if the next decimal
place is 0–4, or up if it’s 5–9).
Truncating is slightly different. This cuts off the number at a set place. In computer
science, this function cuts off any numbers after the decimal point. For example, 12.659
truncated would be 12. The function, again, depends on your language. For example,
trunc(number) will remove the decimal places in the number.

roundDown(2.546,2) will become 2.54. The 0.006 is lost.


roundUp(2.11,1) will become 2.2. An additional 0.09 is added.
round(2.546,2) will become 2.55. The third decimal place is a 6. This is higher than 5
so the second decimal place increases.
trunc(22.3) will become 22. The 0.3 is lost.

A Worked examples
a State the result of the code roundDown(2.956,1).
■ The ‘1’ inside the brackets is the number of decimal places (d.p.).
■ So this function wants the number 2.956 rounded down to 1 d.p.
■ The answer is 2.9.
■ Even though the second d.p. is 5, the roundDown function always takes the number down.
b State the result of the code roundUp(6.95,0).
■ The ‘0’ means there are no d.p. required.
■ The function is to round up, therefore the answer is 7.
c State the result of the code round(2.65,1).
■ The 1 means that 1 d.p. is required, and the code does not state up or down, so it depends on the
next number.
■ The next number is a 5, so it needs to round up.
■ The answer is 2.7 (the 0.05 rounds the 6 up to 7, so 2.65 becomes 2.7).
d State the result of the code trunc(659.451).
trunc removes the decimal places, so the answer is 659.

B Guided questions
Copy out the workings and complete the answers on a separate piece of paper.
1 State the result of the code roundDown(10.5946,3).
Step 1: how many decimal places does the function want? 3 places
Step 2: does the function want the number rounded up, down, or is it dependent on the
next number?
Step 3: what is the answer?

26 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


2 State the result of the code roundUp(193.14,1).

4 Arithmetic operations in a programming language


Step 1: how many decimal places does the function want?
Step 2: does the function want the number rounded up, down, or is it dependent on the
next number?
Step 3: what is the answer?
3 State the result of the code round(4875.6954,3).
Step 1: how many decimal places does the function want?
Step 2: does the function want the number rounded up, down, or is it dependent on the
next number?
Step 3: what is the answer?
4 State the result of the code trunc(49.5123).
trunc removes the decimal places, so write all the numbers that appear before it.

C Practice questions
5 State the result of the code roundDown(65.21,0).
6 State the result of the code roundUp(99.987,2).
7 State the result of the code round(90.541263,3).
8 State the result of the code trunc(100.111).
9 State the result of the code roundDown(456.123,2).
10 State the result of the code roundUp(20.695,0).
11 State the result of the code trunc(65.65).
12 State the result of the code round(999.999,2).

Logical operations
There are a number of logical operations that you may come across in programming.
These are shown in Table 4.2. Some of the symbols may differ slightly depending on the
programming language you are using, e.g. not equal to may be != or <>. Some symbols
may differ from how they are shown in mathematics.

4 Arithmetic operations in a programming language 27


Table 4.2
4 Arithmetic operations in a programming language

Symbol Name Function Example


= or == Equal to Returns true if two values are the same 10 == 20 would be false
10 == 10 would be true
!= or <> Not equal to Returns true if two values are different 10 == 20 would be true
10 == 10 would be false
< Less than Returns true if the first number is 10<20 would be true
smaller than the second 20<10 would be false
> Greater than Returns true if the first number is 10>20 would be false
greater than the second 20>10 would be true
<= Less than or Returns true if the first number is less 10<=20 would be true
equal to than or equal to the second 10<=10 would be true
11<=10 would be false
>= Greater than Returns true if the first number is 11>=10 would be true
or equal to greater than or equal to the second 10>=10 would be true
9>=10 would be false

A Worked examples
a What is the result of 25 <= 60?
Step 1: replace the symbol with its meaning.
25 is less than or greater than 60.
Step 2: is this true?
Yes, so the result is true.
b What is the result of 50 > 50?
Step 1: replace the symbol with the meaning.
50 is greater than 50.
Step 2: is this true?
No, so the result is false.
c What is the result of 100 != 101?
Step 1: replace the symbol with the meaning.
100 is not equal to 101.
Step 2: is this true?
Yes, so the result is true.

28 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


B Guided questions

4 Arithmetic operations in a programming language


Copy out the workings and complete the answers on a separate piece of paper.
1 What is the result of 21 = 25?
Step 1: replace the symbol with the meaning. 21 is the same as 25.
Step 2: is this true?
2 What is the result of 99 >= 98?
Step 1: replace the symbol with the meaning.
Step 2: is this true?
3 What is the result of 932 < 1029?
Step 1: replace the symbol with the meaning.
Step 2: is this true?

C Practice questions
4 What is the result of 20 <= 21?
5 What is the result of 100 > 78?
6 What is the result of 0 != 0?
7 What is the result of 654 < 987?
8 What is the result of 2839 <= 9283?
9 What is the result of 3 >= 3?
10 What is the result of 222 = 111?
11 What is the result of 401 <= 432?

4 Arithmetic operations in a programming language 29


5 Binary numbers

Signed vs unsigned binary


Unit 2 introduced number bases, showing that binary numbers are base 2 numbers. This
means there are two symbols, 1 and 0, that make up the numbers. There are two terms
you may come across: signed binary and unsigned binary.
A signed binary number can be positive or negative. If a binary number is signed, then
the first bit (the most significant bit, the leftmost) will be a 1 if it is a negative number,
or a 0 if it is positive, e.g. 10010111 will be a negative number, whilst 01011011 will be
positive. There are a number of different ways to represent a negative number. One of
these is called two’s complement and you will learn about it later.
An unsigned binary number can only be positive. There is no sign so it can be treated
like the binary numbers you were introduced to in Unit 2. The most significant bit (the
leftmost bit, or first bit) is treated as a number because it does not say if the number is
positive.
In an examination you will be told what form the binary is in, whether it is signed or
unsigned, or if it is in two’s complement. If you are not told anything, then treat it as an
unsigned binary number.

Key values for n bits


For the moment, we’ll just work with unsigned binary numbers. You need to know how
to work out the minimum (smallest) value, the maximum (largest) value and the number
of different values that can be represented by a set number of bits.
For example, if you have a 2-bit number, the minimum value you can store is 0:

Table 5.1

0 0 0+0=0

×21 ×20

If you have a 2-bit number, the maximum value you can store is 3:

Table 5.2

1 1 2+1=3
×21 ×20

The number of different values is 0–3, which is four values.

30 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


There are three steps to follow, which let you work out the smallest number, largest

5  Binary numbers
number and the number of different values.
Step 1: the smallest value is 0.
Step 2: the largest value is (2n − 1) (where n is the number of bits).
Step 3: the number of different values is n (where n is the number of bits).
Let’s try it with the example on page 30.
Step 1: the smallest value is 0 (as proven on page 30).
Step 2: the largest value is 2n − 1 where n is the number of bits, which is 2, so replace n with 2.
2n − 1 = 22 − 1 = 4 − 1 = 3.
Step 3: the number of different values is 2n, 22 = 4.

A Worked examples
a Give the smallest value, largest value and the number of different values that can be stored
with 4 bits.
Step 1: the smallest value = 0
Step 2: the largest value = 2n − 1. There are 4 bits. 24 − 1 = 16 − 1 = 15
Step 3: the number of values = 2n = 24 = 16
The smallest number is 0, the largest number is 15, the number of different values is 16.
b Give the smallest value, largest value and the number of different values that can be stored
with 8 bits.
Step 1: the smallest value = 0
Step 2: the largest value = 2n – 1 = 28 – 1 = 256 – 1 = 255
Step 3: the number of values = 2n = 28 = 256
c Give the smallest value, largest value and the number of different values that can be stored
with 1 bit.
Step 1: the smallest value = 0
Step 2: the largest value = 2n – 1 = 21 – 1 = 2 – 1 = 1
Step 3: the number of values = 2n = 21 = 2

B Guided questions
Copy out the workings and complete the answers on a separate piece of paper.
1 Give the smallest value, largest value and the number of different values that can
be stored with 6 bits.
Step 1: write down the smallest value.
Step 2: write the largest value = 2n – 1 = 26 – 1
Step 3: the number of values = 2n = ?

5 Binary numbers 31
2 Give the smallest value, largest value and the number of different values that can
5 Binary numbers

be stored with 9 bits.


Step 1: write down the smallest value.
Step 2: write the formula and complete it to find the largest value.
Step 3: the number of values = 2n = ?

C Practice questions
3 Give the smallest value, largest value and the number of different values that can be
stored with 7 bits.
4 Give the smallest value, largest value and the number of different values that can be
stored with 10 bits.
5 Give the smallest value, largest value and the number of different values that can be
stored with 11 bits.
6 Give the smallest value, largest value and the number of different values that can be
stored with 16 bits.

Binary addition
This section will show you how to add together two unsigned binary integers. Remember
that unsigned means the binary integer is positive and the most significant bit (leftmost
bit) counts as a value.
Rule 1: 0 + 0 = 0
0 The binary for 0
0 Added to the binary for 0
0 Equals the binary for 0

Rule 2: 0 + 1 = 1 or 1 + 0 = 1
0 The binary for 0
1 Added to the binary for 1
1 Equals the binary for 1

Rule 3: 1 + 1 = 0 carry 1
1 The binary for 1
1 Added to the binary for 1
1 0 Equals the binary for 2 (which is 10)

Rule 4: 1 + 1 + 1 = 1 carry 1
1 The binary for 1
1 Added to the binary for 1
1 Added to the binary for 1
1 1 Equals the binary for 3 (which is 11)

32 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


When performing an addition, you may be given two or more binary numbers to add

5  Binary numbers
together. Put the numbers above each other, with the binary numbers aligned to the right,
then look at each column from the right, one at a time. If there are 8 bits, look at the
column with the 8th bit in and find which rule applies to it. Then move to the 7th. Carried
digits are put in the column to the left, and they count when applying the rules. Let’s see
it in practice.

A Worked examples
a Add the binary numbers 01111011 and 01101000.
Step 1: put the numbers together (these are in a table to help to get you started).

0 1 1 1 1 0 1 1
0 1 1 0 1 0 0 0

Step 2: look at the rightmost column, 1 + 0.


Which rule does this follow? Rule 2. So the answer is 1.

0 1 1 1 1 0 1 1
0 1 1 0 1 0 0 0
1

Step 3: look at the next rightmost column, 1 + 0.


Rule 2 again. Fill in the answer.

0 1 1 1 1 0 1 1
0 1 1 0 1 0 0 0
1 1

Step 4: next column, 0 + 0.


Rule 1. The answer is 0.

0 1 1 1 1 0 1 1
0 1 1 0 1 0 0 0
0 1 1

Step 5: next column, 1 + 1.


Rule 3. The answer is 0, carry 1. The carry goes below the column to the left.

0 1 1 1 1 0 1 1
0 1 1 0 1 0 0 0
0 0 1 1
1

5 Binary numbers 33
Step 6: next column (there is now a bit in the carry that needs to be taken into account). 1 + 0 + 1.
5 Binary numbers

Ignore the 0, there are two 1s, so this follows Rule 3. The answer is 0 carry 1.

0 1 1 1 1 0 1 1
0 1 1 0 1 0 0 0
0 0 0 1 1
1 1

Step 7: next column (including the carry), 1 + 1 + 1.


There are three 1s, so this follows Rule 4. The answer is 1 carry 1.

0 1 1 1 1 0 1 1
0 1 1 0 1 0 0 0
1 0 0 0 1 1
1 1 1

Step 8: next column (including the carry), 1 + 1 + 1.


Rule 4. 1 carry 1.

0 1 1 1 1 0 1 1
0 1 1 0 1 0 0 0
1 1 0 0 0 1 1
1 1 1 1

Step 9: next column (including the carry), 0 + 0 + 1.


There is one 1, so this follows Rule 2. The answer is 1.

0 1 1 1 1 0 1 1
0 1 1 0 1 0 0 0
1 1 1 0 0 0 1 1
1 1 1 1

Once you have completed an addition, convert the binary numbers to check you have done it
correctly.

0 1 1 1 1 0 1 1 = 123
0 1 1 0 1 0 0 0 = 104
1 1 1 0 0 0 1 1 = 227

34 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


5  Binary numbers
b Add the binary numbers 10110110 and 11000111.
Step 1: put the numbers together and complete the rightmost column (two 1s, Rule 3).

1 0 1 1 0 1 1 1
1 1 0 0 0 1 1 1
0
1

Step 2: check the second column (three 1s, Rule 4).

1 0 1 1 0 1 1 1
1 1 0 0 0 1 1 1
1 0
1 1

Continue until the end.

1 0 1 1 0 1 1 1
1 1 0 0 0 1 1 1
0 1 1 1 1 1 1 0
1 1 1 1

There is an extra carry left over on this one. This is called overflow. It means that the two
(in this case) 8-bit numbers added together need more than 8 bits. They need 9. Show this in
the examination to make it clear you know what has happened. You may also be asked what it is
and why it is there.

5 Binary numbers 35
B Guided questions
5 Binary numbers

Copy out the workings and complete the answers on a separate piece of paper.
1 Add the binary numbers 0110 and 1001.
Step 1: put the binary numbers together.

0 1 1 0
1 0 0 1
1

Step 2: work out the rightmost column. 0 + 1 = 1 (Rule 2). Write it in the table.
Step 3: work out the second column. Write it in the table.
Step 4: work out the third column and write it in the table.
Step 5: work out the fourth column and write it in the table.
Step 6: is there an overflow? If so, make sure you include it.
2 Add the binary numbers 01101110 and 11111111.
Step 1: put the binary numbers together.

0 1 1 0 1 1 1 0

Step 2: work out the rightmost column. Write it in the table.


Step 3: work out the next column. Write it in the table.
Step 4: continue working from right to left, filling in the boxes. Do not forget to put
carries underneath and take them into account in each column.
Step 5: is there an overflow? If so, make sure you include it.

C Practice questions
3 Add the binary numbers 01101 and 10110.
4 Add the binary numbers 01110001 and 10001111.
5 Add the binary numbers 10011110 and 11101101.
6 Add the binary numbers 11110110 and 10011111.
7 Add the binary numbers 00001111 and 11111111.
8 Add the binary numbers 100111011011 and 011110111011.

36 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


If you are ever asked to add lots of 1s, e.g. if you are asked to add together three

5  Binary numbers
binary numbers, you can split them up and add two, then the third. Or, if you follow
the patterns above, four 1s equal the number 4. 4 in binary is 100. So put a 0, and
carry the 1 across two columns to the left.

0 0 0 1 1 1 1 1
0 1 0 0 0 1 1 1
1 0 0 0 1 0 1 1
1
1
Put a 0 in the box, and carry to 1 two places to the left.

0 0 0 1 1 1 1 1
0 1 0 0 0 1 1 1
1 0 0 0 1 0 1 1
0 1
1 1
Then continue with the next column.

Binary multiplication
This section will show you how to multiply two unsigned binary integers together.
Remember that unsigned means the binary integer is positive and the most significant bit
(leftmost bit) counts as a value.
As with binary addition, there are rules for binary multiplication.
Rule 1: 0×0=0 Rule 2: 1×0=0 Rule 3: 1×1=1
An easy way to remember these rules is that if there is a 0 involved, the answer is 0.
Multiplication then works in the same way as decimal multiplication.

A Worked examples
Let’s have a go with two digits first.
a Multiply the binary numbers 11 and 10.
Step 1: put the numbers in a table.

1 1
1 0

5 Binary numbers 37
Step 2: multiply the top row by the bottom right number. In this case, 0.
5 Binary numbers

1 1 1 1
1 0 1 0
0 0 0
1×0=0 1×0=0
Step 3: add a 0 on the next row.

1 1
1 0
0 0
0

Step 4: multiply the top row by the next number on row 2. In this case, 1. The answers go to the left
of the 0 you just added.

1 1 1 1
1 0 1 0
0 0 0 0
1 0 1 1 0
1×1=1 1×1=1
Step 5: add the results of the multiplications together.

1 1
1 0
0 0
1 1 0
1 1 0

Let’s check this is correct. 11 = 3, 10 = 2, 3 × 2 = 6 , 110 = 6. Yes, it’s right.

b Multiply the binary numbers 101 and 101.


Step 1: put the numbers in a table.

1 0 1
1 0 1

38 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


Step 2: multiply the top row by the bottom right number. In this case, 1.

5  Binary numbers
1 0 1 1 0 1 1 0 1
1 0 1 1 0 1 1 0 1
1 0 1 1 0 1
1×1=1 0×1=0 1×1=1
Step 3: add a 0 on the next row.

1 0 1
1 0 1
1 0 1
0

Step 4: multiply the top row by the second number on row 2. In this case, 0. The answers go to the
left of the 0 you added in Step 3.

1 0 1 1 0 1
1 0 1 1 0 1
1 0 1 1 0 1
0 0 0 0 0
1×0=0 0×0=0

1 0 1
1 0 1
1 0 1
0 0 0 0
1×0=0
Step 5: add two 0s on the next row.

1 0 1
1 0 1
1 0 1
0 0 0 0
0 0

Each time you move across one bit on the bottom row, you add another 0. So for the
first bit (the rightmost), you add no 0s. For the second, you add one 0. For the third,
you add two 0s. For the fourth, you add three 0s, etc.

5 Binary numbers 39
Step 6: multiply the top row by the third number on row 2. In this case, 1.
5 Binary numbers

The answers go to the left of the 0s you added in Step 5.

1 0 1 1 0 1
1 0 1 1 0 1
1 0 1 1 0 1
0 0 0 0 0 0 0 0
1 0 0 0 1 0 0
1×1=1 0×1=0

1 0 1
1 0 1
1 0 1
0 0 0 0
1 0 1 0 0
1×1=1

Step 7: now you have multiplied all of the top row by all of the bottom row, add together the
resulting numbers.

1 0 1
1 0 1
1 0 1
0 0 0 0
1 0 1 0 0
1 1 0 0 1
1

When adding binary numbers, remember to work from right to left one column at
a time. Check which rule it meets, and don’t forget to include carries. If you do not
want to add all three numbers together, add the first two, then add the third to it.

40 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


B Guided questions

5  Binary numbers
Copy out the workings and complete the answers on a separate piece of paper.
1 Multiply the binary numbers 111 and 001.
Step 1: put the numbers in a table.

1 1 1
0 0 1
1

Step 2: multiply the top row by the bottom right number. Write the result of the
calculation in the boxes of the main table. The first one has been filled in for you.

1 1 1 1 1 1 1 1 1
0 0 1 0 0 1 0 0 1

Step 3: add a 0 in the next row, on the right-hand side.


Step 4: multiply the top row by the second number on row 2. The answers go to the
left of the 0 you added in Step 3.

1 1 1 1 1 1 1 1 1
0 0 1 0 0 1 0 0 1

Step 5: add two 0s in the next row, on the right-hand side.

Step 6: multiply the top row by the third number on row 2. The answers go to the left
of the 0s you added in Step 5.

1 1 1 1 1 1 1 1 1
0 0 1 0 0 1 0 0 1

Step 7: now you have multiplied all of the top row by all of the bottom row, add
together the resulting numbers.

When adding binary numbers, remember to work from right to left one
column at a time. Check which rule it meets, and don’t forget to include
carries. If you do not want to add all three numbers together, add the first two,
then add the third to it.

2 Multiply the binary numbers 111 and 10011.


Step 1: put the numbers in a table. The numbers have a different number of bits. You
need to make them the same, so add 0s to the front of 111, making it 00111.

5 Binary numbers 41
5 Binary numbers

0 0 1 1 1

1 0 0 1 1

Step 2: multiply the top row by the bottom right number. Write the result of the
calculation in the boxes in the main table.

0 0 1 1 1 0 0 1 1 1 0 0 1 1 1
1 0 0 1 1 1 0 0 1 1 1 0 0 1 1

0 0 1 1 1 0 0 1 1 1
1 0 0 1 1 1 0 0 1 1

Step 3: add a 0 in the next row, on the right-hand side.


Step 4: multiply the top row by the second number on row 2. The answers go to the
left of the 0 you added in Step 3.

0 0 1 1 1 0 0 1 1 1 0 0 1 1 1
1 0 0 1 1 1 0 0 1 1 1 0 0 1 1

0 0 1 1 1 0 0 1 1 1
1 0 0 1 1 1 0 0 1 1

Step 5: add two 0s in the next row, on the right-hand side.


Step 6: multiply the top row by the third number on row 2. The answers go to the left
of the 0s you added in Step 5.
Step 7: add three 0s in the next row, on the right-hand side.
Step 8: multiply the top row by the fourth number on row 2. The answers go to the
left of the 0s you added in Step 7.
Step 9: add four 0s in the next row, on the right-hand side.
Step 10: multiply the top row by the fifth number on row 2. The answers go to the left
of the 0s you added in Step 9.
Step 11: now you have multiplied all of the top row by all of the bottom row, add
together the resulting numbers.

42 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


When adding binary numbers, remember to work from right to left one column at

5  Binary numbers
a time. Check which rule it meets, and don’t forget to include carries. If you do not
want to add all three numbers together, add the first two, then add the next to it.
Continue until they are all added together.

C Practice questions
3 Multiply the binary numbers 010 and 111.
4 Multiply the binary numbers 1100 and 0110.
5 Multiply the binary numbers 10111 and 01111.
6 Multiply the binary numbers 11000 and 00011.
7 Multiply the binary numbers 101100 and 0111.
8 Multiply the binary numbers 11110110 and 1101.
9 Multiply the binary numbers 10111110 and 0001101.
10 Multiply the binary numbers 10110101 and 00111101.

Representing negative numbers


As described at the start of this Unit, you can also represent negative numbers in
binary. Two methods of doing this are sign and magnitude and two’s complement.
In an examination, you are usually told if a number is represented using either of these
methods, or if you are required to convert to a negative number.

Sign and magnitude


Sign and magnitude is one method of representing a negative number.
The first bit (the leftmost bit) does not have a numeric value. It represents the sign and is
known as the sign bit. If it is a 1, it is a negative number. If it is a 0, it is positive. If the
number is negative, you do not include this 1 when working out the value. Otherwise you
treat it like a normal binary (base 2) number.

A Worked examples
a Convert the sign and magnitude number 01010111 into a decimal number.
Step 1: work out the decimal, ignoring the sign bit. (0)1010111 = 87
Step 2: is the first bit (in brackets in Step 1) a 1 or 0? If 1, add a ‘–’. It’s a 0, so the number is positive.
As a decimal the number is 87.
b Convert the sign and magnitude number 10111110 into a decimal number.
Step 1: work out the decimal, ignoring the sign bit. (1)0111110 = 62
Step 2: is the first bit a 1 or 0? It’s a 1, so the number is negative. As a decimal the number is –62.

5 Binary numbers 43
5 Binary numbers

c Convert the decimal number 45 into a sign and magnitude number.


Step 1: work out the base 2 (unsigned binary) value. 45 = 101101
Step 2: is the number positive or negative? It is positive, so add a 0 at the front to give 0101101.
d Convert the decimal number –99 into a sign and magnitude number.
Step 1: work out the base 2 (unsigned binary) value. 99 = 1100011
Step 2: is the number positive or negative? It is negative, so add a 1 at the front to give 11100011.

B Guided questions
Copy out the workings and complete the answers on a separate piece of paper.
1 Convert the sign and magnitude number 01100010 into a decimal number.
Step 1: work out the decimal, ignoring the first bit. (0)1100010 =
Step 2: is the first bit (in brackets) a 1 or a 0? If a 1, the number is negative, if a 0,
it’s positive.
2 Convert the sign and magnitude number 10001101 into a decimal number.
Step 1: work out the decimal, ignoring the first bit.
Step 2: is the first bit a 1 or a 0? Is the number positive or negative?
3 Convert the decimal number 68 into a sign and magnitude number.
Step 1: work out the base 2 value.
Step 2: is the number positive or negative? If positive, add a 0 to the front, if
negative, add a 1.
4 Convert the decimal number –102 into a sign and magnitude number.
Step 1: work out the base 2 value.
Step 2: is the number positive or negative? Add a 0 or a 1 to the front.

C Practice questions
5 Convert the sign and magnitude number 01011 into a decimal number.
6 Convert the sign and magnitude number 11001 into a decimal number.
7 Convert the sign and magnitude number 01011001 into a decimal number.
8 Convert the sign and magnitude number 10111011 into a decimal number.
9 Convert the decimal number 55 into a sign and magnitude number.
10 Convert the decimal number –55 into a sign and magnitude number.
11 Convert the decimal number 150 into a sign and magnitude number.
12 Convert the decimal number –174 into a sign and magnitude number.

44 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


Two’s complement

5  Binary numbers
In two’s complement, positive binary numbers are represented in the usual way.
Negative numbers are represented in a way that, in computing, behaves like the
negative of the original number.

Denary to two’s complement


If the denary number is positive, then conversion is the same as to binary. However,
because it is positive the first bit (the most significant bit) must be a 0 to show it is
positive. (For notes on how to convert to binary see page 16 in Unit 2.)
For example, 23 in binary is 10111. However, this starts with a 1, which would indicate
that the number is negative. Add a 0 at the front to indicate that it is positive: 010111.
If the denary number is negative, then convert it to two’s complement form. There are
a number of ways of doing this, but we’ll stick with one method here. You convert the
denary number to binary (as normal), then flip every bit (if it’s a 1, replace it with a 0, if
it’s a 0 replace it with a 1), then add binary 1 to it.

A Worked examples
a Convert the denary number –35 into two’s complement.
Step 1: write +35 in binary (add 0 at the left to show it is positive).
0100011
Step 2: is the number you are converting negative? Yes, so flip every bit.
1011100
Step 3: add 1.
1 0 1 1 1 0 0
+ 0 0 0 0 0 0 1
1 0 1 1 1 0 1

Step 4: write the answer.


1011101
b Convert the denary number –149 into two’s complement.
Step 1: write +149 in binary (add 0 at the left to show it is positive).
010010101
Step 2: is the number you are converting negative? Yes, so flip every bit.
101101010
Step 3: add 1.
1 0 1 1 0 1 0 1 0
+ 0 0 0 0 0 0 0 0 1
1 0 1 1 0 1 0 1 1

Step 4: write the answer.


101101011

5 Binary numbers 45
c Convert the denary number 200 into two’s complement.
5 Binary numbers

Step 1: write +200 in binary (add 0 at the left to show it is positive).


011001000
Step 2: is the number you are converting negative? No, so double check there is a 0 at the front.
There is.
Step 3: write the answer.
011001000

B Guided questions
Copy out the workings and complete the answers on a separate piece of paper.
1 Convert the denary number 40 into two’s complement.
Step 1: write +40 in binary (make sure it is positive).
0101000
Step 2: is the number you are converting negative? No, so double check there is a 0 at
the front.
Step 3: write the answer.
2 Convert the denary number –83 into two’s complement.
Step 1: write +83 in binary (make sure it is positive).
01010011
Step 2: is the number you are converting negative? Yes, so flip every bit.
Step 3: add 1.
Step 4: write the answer.
3 Convert the denary number –200 into two’s complement.
Step 1: write +200 in binary (make sure it is positive).
Step 2: is the number you are converting negative? Yes, so flip every bit.
Step 3: add 1.
Step 4: write the answer.

C Practice questions
4 Convert the denary number +55 into two’s complement.
5 Convert the denary number +202 into two’s complement.
6 Convert the denary number –13 into two’s complement.
7 Convert the denary number –99 into two’s complement.
8 Convert the denary number +123 into two’s complement.
9 Convert the denary number –123 into two’s complement.

46 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


10 Convert the denary number –239 into two’s complement.

5  Binary numbers
11 Convert the denary number –302 into two’s complement.
12 Convert the denary number +321 into two’s complement.
13 Convert the denary number –400 into two’s complement.

Two’s complement to denary


If you are given a number in two’s complement and
asked to convert it to denary, first check if it is positive or Remember that denary
negative. Look at the first (leftmost) bit. If this is a 1 the means base 10 (otherwise
known as decimal).
number is negative. If this is a 0 the number is positive.
If the number is positive, then convert it like an ordinary binary number, e.g.
01101011 = 107
If it is negative, then you need to reverse the ‘flipping’. The easiest way to do this is: from
right to left, write all the bits up to and including the first 1, then flip the remaining bits
to the left of this 1.

A Worked examples
a Convert the two’s complement number 1010 into denary.
Step 1: is the number you are converting negative? Yes.
Step 2: from right to left, write all the bits up to and including the first 1 and flip the rest.

Before 1 0 1 0
After 0 1 1 0

Step 3: treat it as a positive binary number and convert it to denary, 0110 = 6.


Step 4: write the answer with a ‘–’, –6.
b Convert the two’s complement number 110110 into denary.
Step 1: is the number you are converting negative? Yes.
Step 2: from right to left, write all the bits up to and including the first 1 and flip the rest.

Before 1 1 0 1 1 0
After 0 0 1 0 1 0

Step 3: treat it as a positive binary number and convert it to denary, 001010 = 10.
Step 4: write the answer with a ‘–’, –10.
c Convert the two’s complement number 010110 into denary.
Step 1: is the number you are converting negative? No.
Step 2: convert it as a positive binary number, 010110 = 22.

5 Binary numbers 47
B Guided questions
5 Binary numbers

Copy out the workings and complete the answers on a separate piece of paper.
1 Convert the two’s complement number 01011 into denary.
Step 1: is the number you are converting negative? No.
Step 2: convert it as a positive binary number.
2 Convert the two’s complement number 100010 into denary.
Step 1: is the number you are converting negative? Yes.
Step 2: from right to left, write all the bits up to and including the first 1 and flip the rest.
Step 3: treat it as a positive binary number and convert it to denary.
Step 4: write the answer with a ‘–’.
3 Convert the two’s complement number 11110001 into denary.
Step 1: is the number you are converting negative?
Step 2: from right to left, write all the bits up to and including the first 1 and flip the
rest.
Step 3: treat it as a positive binary number and convert it to denary.
Step 4: write the answer with a ‘–’.

C Practice questions
4 Convert the two’s complement number 010101 into denary.
5 Convert the two’s complement number 11011000 into denary.
6 Convert the two’s complement number 10110010 into denary.
7 Convert the two’s complement number 01011011 into denary.
8 Convert the two’s complement number 0101111101 into denary.
9 Convert the two’s complement number 1110001010 into denary.
10 Convert the two’s complement number 1011010101 into denary.
11 Convert the two’s complement number 0101100001 into denary.
12 Convert the two’s complement number 0101111001010100 into denary.
13 Convert the two’s complement number 1010011001001010 into denary.

Range of two’s complement numbers


Two’s complement numbers can represent a different range of numbers than an unsigned
binary number, e.g. unsigned 8 bits can store 0 to 255, whilst two’s complement 8 bits
can store –127 to +127. The positive range (in this case 127) can be generated using the
formula 2n–1 –1, where n is the number of bits.
For example, if there are 6 bits, using this formula, the range is:
26−1 − 1 = 25 − 1 = 32 − 1 = 31

48 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


A Worked example

5  Binary numbers
What is the range of numbers that can be stored in two’s complement with 5 bits?
2n−1 −1 = 25−1 − 1 = 24 − 1 = 16 − 1 = 15
The range is –15 to +15.

B Guided questions
Copy out the workings and complete the answers on a separate piece of paper.
1 What is the range of numbers that can be stored in two’s complement with 10 bits?
Copy the line below and fill in the gaps. Remember that n is the number of bits (10).
2n−1 − 1 = 2 −1= −1= =
2 What is the range of numbers that can be stored in two’s complement with 12 bits?
Copy the line below and fill in the gaps
2n−1 − 1 = 2 −1= −1=

C Practice questions
3 What is the range of numbers that can be stored in two’s complement with 3 bits?
4 What is the range of numbers that can be stored in two’s complement with 7 bits?
5 What is the range of numbers that can be stored in two’s complement with 11 bits?
6 What is the range of numbers that can be stored in two’s complement with 13 bits?
7 What is the range of numbers that can be stored in two’s complement with 16 bits?

Subtracting with two’s complement


You can use two’s complement numbers to perform binary subtraction. Subtracting is
the same as adding a negative number, e.g. 12 – 3 is the same as 12 + (–3). If you turn the
second number into a negative using two’s complement, then you can add the two numbers
together. (For notes on binary addition see page 32.)

A Worked examples
a Perform the binary subtraction of 12 – 3.
Step 1: turn it into an addition. 12 + –3.
Step 2: turn the first number into binary (make sure it is positive with a 0 at the front). 12 = 01100
Step 3: turn the second number into two’s complement.
+3 = 0011
−3 = 1101
Step 4: put the two numbers in a table ready to add together. Make sure they both have the same number
of bits by adding 0s at the front of the positive number, or 1s at the front of the negative number.

5 Binary numbers 49
5 Binary numbers

+12 0 1 1 0 0
–3 1 1 1 0 1
0 1 0 0 1
1 1 1

There will be an overflow, but you don’t need to worry about it when subtracting. Just ignore it.
The answer is 01001.
b Perform the binary subtraction of 53 – 15.
Step 1: turn it into an addition. 53 + –15
Step 2: turn the first number into binary. 53 = 0110101
Step 3: turn the second number into two’s complement.
+15 = 01111
−15 = 10001
Step 4: put the numbers in a table and add them. (Fill in any gaps so they are the same length.)

+53 0 1 1 0 1 0 1
–15 1 1 1 0 0 0 1
0 1 0 0 1 1 0
1 1 1 1

The answer is 0100110.

B Guided questions
Copy out the workings and complete the answers on a separate piece of paper.
1 Perform the binary subtraction 31 – 4.
Step 1: turn it into addition. 31 + −4
Step 2: turn the first number (31) into binary.
Step 3: turn the second number (–4) into two’s complement (binary first, then flip
and add 1).
Step 4: put the numbers in a table and add them.
2 Perform the binary subtraction 99 – 45.
Step 1: turn it into addition.
Step 2: turn the first number into binary.
Step 3: turn the second number into two’s complement.
Step 4: put the numbers in a table and add them.

50 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


C Practice questions

5  Binary numbers
3 Perform the binary subtraction 10 – 2.
4 Perform the binary subtraction 50 – 6.
5 Perform the binary subtraction 101 – 12.
6 Perform the binary subtraction 155 – 4.
7 Perform the binary subtraction 200 – 200.
8 Perform the binary subtraction 212 – 99.
9 Perform the binary subtraction 200 – 197.
10 Perform the binary subtraction 230 – 19.
11 Perform the binary subtraction 255 – 184.
12 Perform the binary subtraction 356 – 287.

Fixed point
It is possible to store denary, or fractional, numbers in binary. This is usually called fixed
point binary. It includes a point separating the whole-number part and the fractional part.
The binary digits after the point are represented by 2−1, 2−2, etc. from left to right.

Fixed point to denary


To convert a fixed point binary to a denary number follow these steps.
Step 1: put the fixed point number into a table such as the one shown.

.
× 23 × 22 × 21 × 20 . × 2–1 × 2–2

Step 2: calculate each multiplication.


Step 3: add the results.
Fixed point numbers can also be in two’s complement. If a question does not say two’s
complement is being used, then the number is unsigned — you do not need to worry
about negatives.

5 Binary numbers 51
A Worked example
5 Binary numbers

Convert the fixed point number 1011.01 to denary.


Step 1 and Step 2: write the bits in a table and calculate each multiplication (see table).
1 0 1 1 . 0 1
×2 3
×2 2
×2 1
×2 0
. ×2 –1
× 2–2
8 0 2 1 0.5 0.25

Step 3: add the results. Answer: 11.75

Denary to fixed point


To convert an unsigned, whole denary number, you keep dividing by 2 to find the binary
value. To convert fixed point numbers, you do this with the number before the binary point.
With the numbers after the binary point, you multiply the fractional part by 2 until you get
1.0, and write the binary from top to bottom using the digit before the decimal point in each
calculation. (For notes on how to convert a denary number to binary see page 16 in Unit 2.)

A Worked example
Convert the denary number 20.34375 to fixed point.
Step 1: write the binary for 20 = 10100.
Step 2: multiply the fractional part (0.34375) by 2: 0.34375 × 2 = 0.6875
Then multiply the fractional part (0.6875) by 2: 0.6875 × 2 = 1.375
Continue multiplying each fractional part by 2: 0.375 × 2 = 0.75
0.75 × 2 = 1.5
0.5 × 2 = 1.0
Step 3: write the binary for the fraction (top to bottom): 01011
So the answer is 10100.01011

B Guided questions
Copy out the workings and complete the answers on a separate piece of paper.
1 Convert the fixed point number 0110.11 to denary.
Step 1: copy the table and write the bits in the first row. The integer part has been
done for you.

0 1 1 0 .
× 23 × 22 × 21 × 20 . × 2–1 × 2–2
0 4

Step 2: write the results of each multiplication. The first two have been done for you.
Step 3: add the results.

52 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


2 Convert the fixed point number 10011011.1010 to denary.

5  Binary numbers
Step 1: copy the table and write the bits in the first row.

.
× 27 × 26 × 25 × 24 × 23 × 22 × 21 × 20 . × 2–1 × 2–2 × 2–3 × 2–4

Step 2: write the results of each multiplication in the third row of the table.
Step 3: add the results.
3 Convert the denary number 13.125 to fixed point.
Step 1: write the binary for 13.
Step 2: multiply the fractional part (0.125) by 2: ×2=
Then multiply the fractional part by 2: ×2=
×2=
Step 3: write the binary for the fraction (top to bottom):
The answer is
4 Convert the denary number 6.3125 to fixed point.
Step 1: write the binary for 6.
Step 2: multiply the fractional part (0.3125) by 2: ×2=
Then multiply the fractional part by 2: ×2=
×2=
×2=
Step 3: write the binary for the fraction (top to bottom):
The answer is

C Practice questions
5 Convert the fixed point number 0101.111 to denary.
6 Convert the fixed point number 11011.1001 to denary.
7 Convert the fixed point number 110111.001 to denary.
8 Convert the fixed point number 111001.01011 to denary.
9 Convert the fixed point number 10101010.11001 to denary.
10 Convert the denary number 5.125 to fixed point.
11 Convert the denary number 12.625 to fixed point.
12 Convert the denary number 20.75 to fixed point.
13 Convert the denary number 36.3125 to fixed point.
14 Convert the denary number 45.4296875 to fixed point.

5 Binary numbers 53
Logical shifts
5 Binary numbers

Note: this topic is assessed at A-level only.


A logical shift means moving the bits in binary numbers to the left or right a set
number of places. It represents multiplying or dividing by powers of 2.

Left shift
A left shift involves moving all the bits to the left, and adding 0s on the right. If it’s a
2-place shift, you add two 0s to the right-hand side. If there is a binary point, then you
move the binary point to the right.
Each shift to the left means the number has been multiplied by 2. A 2-place shift means
the number is multiplied by 4, a 3-place shift means the number is multiplied by 8.
If a question asks for the number to remain a set number of bits, e.g. an 8-bit number,
then you would need to remove bits on the left. For example:

0 1 1 0 1 0 1 0

Performing a 1-place left shift to this binary number gives you:

1 1 0 1 0 1 0 0

A Worked examples
a Perform a 2-place left shift on the binary number 00011011.
Add two 0s on the right-hand side: 0001101100
b Perform a 3-place left shift on the binary number 000110.11.
Move the binary point three places to the right. If more bits are needed, add 0s. 000110110
c Show the effect of a 3-place left shift on the binary number 010110110.
Step 1: work out the denary value before the shift: 010110110 = 182
Step 2: add three 0s on the right-hand side: 010110110000
Step 3: work out the denary value after the shift: 010110110000 = 1456
This is a 3-place shift, so the number is multiplied by 8, 182 × 8 = 1456
d Perform a 4-place left shift on the binary number 10010110. Give the result as an 8-bit number.
Step 1: add four 0s on the right-hand side: 100101100000
Step 2: remove 4 bits from the front of the number to make it 8 bits: 01100000

Right shift
A right shift involves moving all the bits to the right. You need to add the binary point
before you make the move, as this will move to the left.
Each shift to the right means the number has been divided by 2. A 2-place shift means
the number is divided by 4, a 3-place shift means the number is divided by 8.

54 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


A Worked examples

5  Binary numbers
a Perform a 2-place right shift on the binary number 01101010.
Step 1: add the binary point: 01101010.
Step 2: move the binary point two places to the left: 011010.10
b Perform a 3-place right shift on the binary number 10110101.
Step 1: add the binary point: 10110101.
Step 2: move the binary point three places to the left: 10110.101
c Show the effect of a 2-place right shift on the binary number 01011010.
Step 1: work out the denary value before the shift: 01011010 = 90
Step 2: add the binary point: 01011010.
Step 3: move the binary point two places to the left: 010110.10
Step 4: work out the denary value after the shift: 010110.10 = 22 12
This is a 2-place shift, so the number is divided by 4, 90 ÷ 4 = 22 12

B Guided questions
Copy out the workings and complete the answers on a separate piece of paper.
1 Perform a 1-place left shift on the binary number 10101101.
Add one 0 on the right-hand side.
2 Perform a 1-place right shift on the binary number 01100101.
Step 1: add the binary point: 01100101.
Step 2: move the binary point one place to the left.
3 Perform a 3-place left shift on the binary number 0101101.1.
Move the binary point three places to the right. Add more 0s if needed.
4 Perform a 4-place right shift on the binary number 01011111.
Step 1: add the binary point.
Step 2: move the binary point four places to the left.
5 State the effect of a 3-place left shift on a binary number.
Each shift left multiplies it by 2, so a 1-shift is multiplied by 2, a 2-shift is multiplied
by 4, and a 3-shift is
6 State the effect of a 4-place right shift on a binary number.
Each shift right divides by 2, so a 1-shift divides the number by 2, a 2-shift
divides the number by 4, a 3-shift divides the number by 8, a 4-shift divides the
number by

5 Binary numbers 55
C Practice questions
5 Binary numbers

7 Perform a 2-place left shift on the binary number 11110100.


8 Perform a 2-place right shift on the binary number 01000011.
9 Perform a 3-place left shift on the binary number 10110000. Give your answer as an
8-bit number.
10 Perform a 3-place right shift on the binary number 01100001.
11 State the effect of a 2-place left shift on a binary number.
12 State the effect of a 5-place right shift on a binary number.
13 Perform a 6-place left shift on the binary number 011011.11.
14 Perform a 5-place right shift on the binary number 0110.

Bitwise operators
Note: this topic is assessed at A-level only.
There are four operators that you need to be able to apply to either one or more binary
numbers. These are NOT, OR, AND and XOR. They act in the same way as in logic
gates and binary logic.

NOT
A NOT function changes a 0 to a 1, and a 1 to a 0.

AND
An AND function takes two binary numbers. If they are both 1, the answer is 1. If either
is 0, the answer is 0.

OR
An OR function takes two binary numbers. If one or both are 1, the answer is 1. If both
are 0, the answer is 0.

XOR
XOR (exclusive OR) takes two binary numbers. If they are both 0, or both 1, the result is
0. If only one is a 1, the answer is 1.
When the AND, OR or XOR are applied, you need two binary numbers. One of these
may be referred to as a ‘mask’. This just means it is the binary number you are using to
complete the operation.

56 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


A Worked examples

5  Binary numbers
a Perform the bitwise NOT operation on 1011.
Reverse each of the bits to give 0100.
b Perform a bitwise AND operation on 1011 with the mask 0111.
Step 1: put the numbers above each other, like in an addition.

1 0 1 1
0 1 1 1
0 0 1 1

Step 2: compare each pair of bits in turn. If they are both 1, the result is 1, otherwise the result is 0.
c Perform a bitwise OR operation on 1011 with the mask 0111.
Step 1: put the numbers above each other.

1 0 1 1
0 1 1 1
1 1 1 1

Step 2: compare each pair of bits in turn. If either or both are 1s, the result is 1, otherwise the result
is 0.
d Perform a bitwise XOR operation on 1011 with the mask 0111.
Step 1: put the numbers above each other.

1 0 1 1
0 1 1 1
1 1 0 0

Step 2: compare each pair of bits in turn. If both are 0s or 1s, the result is 0, otherwise the result is 1.

B Guided questions
Copy out the workings and complete the answers on a separate piece of paper.
1 Perform a bitwise NOT operation on 01011011.
Reverse each of the bits.
2 Perform a bitwise AND operation on 010110 with the mask 101101.
Step 1: put the numbers above each other, like in an addition.

0 1 0 1 1 0
1 0 1 1 0 1
0 0

Step 2: compare each pair of bits in turn. If they are both 1, the result is 1, otherwise
the result is 0.

5 Binary numbers 57
3 Perform a bitwise OR operation on 10101110 with the mask 00110110.
5 Binary numbers

Step 1: put the numbers above each other.

1 0 1 0 1 1 1 0
0 0 1 1 0 1 1 0
1 0

Step 2: compare each pair of bits in turn. If either or both are 1s, the result is 1,
otherwise the result is 0.
4 Perform a bitwise XOR operation on 10101101 with the mask 10100010.
Step 1: put the numbers above each other.

1 0 1 0 1 1 0 1
1 0 1 0 0 0 1 0
0 0

Step 2: compare each pair of bits in turn. If both are 0s or 1s, the result is 0, otherwise
the result is 1.

C Practice questions
5 Perform a bitwise NOT operation on 10101101.
6 Perform a bitwise NOT operation on 01000110.
7 Perform a bitwise AND operation on 01011011 with the mask 10111111.
8 Perform a bitwise AND operation on 10111101 with the mask 00001000.
9 Perform a bitwise OR operation on 00101011 with the mask 10111011.
10 Perform a bitwise OR operation on 11101111 with the mask 10111010.
11 Perform a bitwise XOR operation on 01000010 with the mask 10101011.
12 Perform a bitwise XOR operation on 11101111 with the mask 01101100.

58 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


6 Floating point data representation

Representation of real numbers in binary


In binary, each column (moving from right to left) represents increasing powers of 2.
This means that 15 can be represented by 1111 (8 + 4 + 2 + 1). If a point is inserted to the
right of this, each continued column to the right represents decreasing powers of 2, as in
the example below:

Table 6.1
1 1 1 0 . 1 1
× 23 × 22 × 21 × 20 × 2–1 × 2–2

1110.11 in binary therefore represents 14.75 (8 + 4 + 2 + 0.5 + 0.25). This system is


known as fixed point binary as the binary point is always fixed in the same place.

Another method is to note that the value of each column to the left of the binary
point doubles in value, from 1 to 2, then 4 and so on. To the right of the binary point,
each column halves in value, from 0.5 to 0.25, then 0.125 and so on. This may be
easier than working out powers of 2 every time!

However, it is inefficient to store very small or very large numbers in this way, so a
system called floating point binary is used instead.

Floating point binary


Floating point binary is very similar to standard form that you may be used to from
GCSE Mathematics or Science. A binary floating point number is written in the form
a.aa × 2b , where a is known as the mantissa and b is the exponent. To calculate the
denary value, simply move the binary point in the mantissa right the number of places
given in the exponent, and convert the answer to denary.
The mantissa and exponent are stored together as one string of binary digits (bits). All
questions will tell you how many bits are used for the mantissa and how many bits are
used for the exponent. The binary point is always placed between the first two digits of
the mantissa.
As the mantissa or exponent could be negative, two’s complement is usually used for
both, but this should always be stated in the question. This means that the leftmost digit
is 1 if negative and 0 if positive. The inclusion of binary places does not change this.

6 Floating point data representation 59


A Worked examples
6 Floating point data representation

a Calculate the denary value of the floating point binary number 0010101010110, where 9 bits
are used for the mantissa followed by 4 bits for the exponent, both in two’s complement.
Step 1: split the binary number into the mantissa (0.01010101) and the exponent (0110).
Step 2: calculate the denary value of the exponent. 0110 = 6
Step 3: move the binary point in the mantissa six places to the right. 0010101.01
Step 4: the mantissa is now 0010101.01 — converting to denary gives (16 + 4 + 1 + 0.25) = 21.25
b Calculate the denary value of the floating point binary number 011110, where 3 bits are used
for the mantissa followed by 3 bits for the exponent, both in two’s complement.
Step 1: split the binary number into the mantissa (0.11) and the exponent (110).
Step 2: calculate the denary value of the exponent. 110 = –4 + 2 = –2
Step 3: because the exponent is negative, the binary point in the mantissa is moved left two places
instead of right.
Step 4: the mantissa is now 0.0011 (added zeros are needed when moving the point). Converting to
denary gives: 0.125 + 0.0625 = 0.1875

B Guided questions
Copy out the workings and complete the answers on a separate piece of paper.
1 Calculate the denary value of the floating point binary number 1011001011,
where 7 bits are used for the mantissa followed by 3 bits for the exponent, both
in two’s complement.
Step 1: split the binary number into the mantissa (7 bits) and the exponent (3 bits).
Step 2: calculate the denary value of the exponent.
Step 3: in this case, the answer from Step 2 is positive, so move the binary point in
the mantissa this many places right.
Step 4: fill in your answer from Step 3 in a table like the one below. Use this to
calculate the denary value. Don’t forget that two’s complement is being used, so the
leftmost bit is negative.

.
× −23 × 22 × 21 × 20 × 2−1 × 2−2 × 2−3

2 Calculate the denary value of the floating point binary number 010111, where
4 bits are used for the mantissa followed by 2 bits for the exponent, both in two’s
complement.
Step 1: split the binary number into the mantissa (4 bits) and the exponent (2 bits).
Step 2: calculate the denary value of the exponent. Remember, two’s complement is
being used.

60 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


Step 3: in this case, the answer from Step 2 is negative, so move the binary point in

6  Floating point data representation


the mantissa this many places left.
Step 4: fill in your answer from Step 3 in a table like the one below. Use this to
calculate the denary value. Don’t forget that two’s complement is being used, so the
leftmost bit is negative.

.
× −20 × 2−1 × 2−2 × 2−3 × 2−4

C Practice question
3 Calculate the denary values of the following floating point binary numbers.
All values are given in two’s complement.
a 010110010101 (8 bits mantissa, 4 bits exponent)
b 100111110110 (8 bits mantissa, 4 bits exponent)
c 0111001010 (6 bits mantissa, 4 bits exponent)
d 0101101110101 (9 bits mantissa, 4 bits exponent)
e 1011111010 (4 bits mantissa, 6 bits exponent)
f 0111100101010 (8 bits mantissa, 5 bits exponent)
g 010111010000 (6 bits mantissa, 6 bits exponent)
h 10100011001100 (6 bits mantissa, 6 bits exponent)

Normalisation
In this context, normalisation is the process of maximising the precision of a number
when storing it in a given number of bits. To do this for a positive binary number involves
removing any leading zeros. To do the same for a negative binary number involves
removing any leading ones. This means that a normalised floating point number must
always start as either 0.1 or 1.0.

Normalisation is also the name given to the process of simplifying the design of
relational databases. This is completely unrelated — do not get confused!

To normalise a floating point binary number, you simply move the binary point in the
mantissa right or left until the above is true. The exponent is then decreased (if the binary
point is moved right) or increased (if moved left) by the number of places moved.

6 Floating point data representation 61


A Worked examples
6 Floating point data representation

a The floating point binary number 000101010101 has an 8-bit mantissa followed by a 4-bit
exponent, both in two’s complement. Find the normalised version of this number.
Step 1: split the binary number into the mantissa (0.0010101) and the exponent (0101).
Step 2: move the binary point in the mantissa right until it starts as 0.1 or 1.0. Moving it two places
ensures that the mantissa is now 0.10101.
Step 3: however, the mantissa is now only 6 digits in length, so add two zeros to the right-hand side.
This keeps it at 8 digits (as required by the question) but does not change the value. The mantissa is
now 0.1010100.
Step 4: as the binary point has been moved two places right, the exponent must be decreased by 2.
The exponent is currently 0101 (5 in denary), so subtracting 2 from this gives 0011 (3).
Step 5: join together the new mantissa and exponent in the format given in the question. In this
case, the normalised value is 010101000011.
b Give the denary value 27.75 as a normalised floating point binary number, using 8 bits for the
mantissa and 4 bits for the exponent, both in two’s complement.
Step 1: write 27.75 as a fixed point binary number using two’s complement = 011011.11.
Step 2: move the binary point five places to the left so that the mantissa is normalised (giving
0.1101111).
Step 3: the binary point was moved five places left, so increase the exponent by 5. (The exponent is
currently 0, so 0 + 5 = 5.) This is 0101 in two’s complement binary.
Step 4: join together the new mantissa and exponent in the format given in the question. In this
case, the normalised value is 011011110101.

B Guided questions
Copy out the workings and complete the answers on a separate piece of paper.
1 State whether each of these floating point binary numbers is normalised or not:
a 1011011011
b 0011001010
c 1010010100
■ To be normalised, a floating point number must start with 10 or 01.
■ Identify which numbers above meet this pattern. These are normalised. Any
numbers starting 00 or 11 are not normalised.
2 The floating point binary number 0011110011 has a 7-bit mantissa followed by
a 3-bit exponent, both in two’s complement. Find the normalised version of this
number.
Step 1: split the binary number into the mantissa (7 bits) and the exponent (3 bits). Put
the binary point between the first two digits of the mantissa.
Step 2: move the binary point in the mantissa right until it starts as 0.1, trimming off
any leading zeros. Note how many places this had to be moved.

62 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


Step 3: add additional zeros to the right-hand side to keep the mantissa as 7 bits in

6  Floating point data representation


length without affecting the value.
Step 4: decrease the exponent by the number of places moved right in Step 2.
Step 5: join together the new mantissa and exponent in the format given in the question.
3 The floating point binary number 111010010001 has an 8-bit mantissa followed
by a 4-bit exponent, both in two’s complement. Find the normalised version of
this number.
Step 1: split the binary number into the mantissa (8 bits) and the exponent (4 bits). Put
the binary point between the first two digits of the mantissa.
Step 2: as the mantissa starts with a 1, it is a negative number. Move the binary point
in the mantissa right until it starts as 1.0, trimming off any leading 1s. Note how
many places this had to be moved.
Step 3: add additional zeros to the right-hand side to keep the mantissa as 8 bits in
length without affecting the value.
Step 4: decrease the exponent by the number of places moved right in Step 2. In this
case, this will mean a negative exponent. Remember to use two’s complement for this.
Step 5: join together the new mantissa and exponent in the format given in the question.

C Practice questions
4 State whether each of these floating point binary numbers is normalised or not:
a 0010110101
b 1101011010
c 0110110101
5 Give the normalised versions of each of the following floating point binary numbers.
Both the mantissa and exponent are in two’s complement.
a 001010000100 (8 bits mantissa, 4 bits exponent)
b 000010110111 (8 bits mantissa, 4 bits exponent)
c 1101000011 (6 bits mantissa, 4 bits exponent)
d 1010010 (4 bits mantissa, 3 bits exponent)
e 001101011001 (8 bits mantissa, 4 bits exponent)
6 Give the normalised floating point binary version of the following denary numbers,
using two’s complement, 8 bits for the mantissa and 4 bits for the exponent.
a 11.375
b 6.875

Range and precision


When representing real numbers using floating point binary, the number of bits used for the
mantissa and exponent affects both the range and precision of the number stored. If the size
of the exponent is increased, then larger numbers can be stored. However, this will leave less
room for the mantissa, so the number will have less precision. Conversely, a larger mantissa
will mean a more precise representation but at the expense of a smaller exponent and so a
smaller range. Precision will be covered in more detail in the next section on ‘Errors’.

6 Floating point data representation 63


For the rest of this Unit, you should assume that all numbers are represented using
6 Floating point data representation

two’s complement.

A Worked examples
a Calculate the largest number that can be stored using an 8-bit binary number if the number
uses 3 bits for the mantissa and 5 bits for the exponent.
Step 1: with 3 bits for the mantissa and 5 bits for the exponent, then the largest number that can be
represented is 01101111.
Step 2: the mantissa is therefore 0.11, with the binary point needing to be moved 15 places to the
right (the exponent 01111 = 15).
Step 3: convert to denary. 0110000000000000 = 8192 + 16 384 = 24 576. This means that the largest
denary number that can be stored in this format is 24 576.
b Calculate the largest number that can be stored using an 8-bit binary number if the number
uses 5 bits for the mantissa and 3 bits for the exponent.
Step 1: with 5 bits for the mantissa and 3 bits for the exponent, the largest number that can be
represented is 01111011.
Step 2: the mantissa is therefore 0.1111, with the binary point needing to be moved three places to the
right (011 = 3). This means that the largest denary number that can be stored in this format is 7.5.
Step 3: convert to denary. 0111.1 = 7.5.

B Guided questions
Copy out the workings and complete the answers on a separate piece of paper.
1 Calculate the largest number that can be stored using a 12-bit binary number
if the number uses 8 bits for the mantissa and 4 bits for the exponent.
Step 1: write down the maximum value that can be stored in the mantissa and the
exponent. Because of two’s complement, this will be entirely 1s, except for the
first digit of each, which will be 0.
Step 2: insert the binary point correctly into the mantissa and then move this to the
right the number of times indicated by the exponent.
Step 3: convert to denary.
2 Calculate the largest number that can be stored using a 12-bit binary number if
the number uses 7 bits for the mantissa and 5 bits for the exponent.
Step 1: write down the maximum value that can be stored in the mantissa and the exponent.
Step 2: insert the binary point correctly into the mantissa and then move this as needed.
Step 3: convert to denary.

64 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


C Practice question

6  Floating point data representation


3 Calculate the largest number that can be stored if the number uses:
a 9 bits, 6 bits for the mantissa and 3 bits for the exponent.
b 9 bits, 5 bits for the mantissa and 4 bits for the exponent.
c 6 bits, 3 bits for the mantissa and 3 bits for the exponent.
d 6 bits, 4 bits for the mantissa and 2 bits for the exponent.
e 6 bits, 2 bits for the mantissa and 4 bits for the exponent.

Errors
Because of the trade-off between range and precision, the representation of some floating
point binary numbers may not always be as precise as we would like. For example, if the
number 76.65625 were to be stored, the full representation would be 0100110010101 for
the mantissa (13 bits) and 0111 for the exponent (4 bits). If, however, only 10 bits were
made available for the mantissa, then this would effectively lose the three leftmost bits,
leaving us with a representation of 76.625. This is very close, but not as precise as before.
This error can be described as an absolute or relative error. The absolute error is the
difference in value between the original number and the representation. This is found by
subtracting one from the other. The relative error is the absolute error expressed as a
percentage of the true value.

A Worked examples
a When the number 76.65625 is represented using 10 bits for the mantissa and 4 bits for the
exponent, the actual value stored is 76.625 (see above for further explanation). Calculate the
absolute and relative errors.
Step 1: the absolute error is the difference between the two values. 76.65625 – 76.625 = 0.013125
Step 2: to find the relative error, find the absolute error as a percentage of the true value. To do this
0.013125
use the formula × 100. This is × 100 = 0.017%
absolute error
true value 76.65625

b Find the absolute and relative errors when the value 3366 is represented using 8 bits for the
mantissa and 5 bits for the exponent.
Step 1: find the fixed point binary representation of 3366. This is 0110100100110 (there are no
fractional parts yet, so the binary point would be to the right-hand side of the rightmost bit).
Step 2: normalise this number and work out the mantissa and exponent. This gives a mantissa of
0.110100100110 and an exponent of 12, which is 01100.
Step 3: to fit the 13-bit mantissa into the 8 bits available, the rightmost 5 bits will need to be lost.
This will give us a new mantissa of 0.1101001.
Step 4: the new mantissa is 0.1101001 and the exponent is 01100. Calculate the value of this in
denary, which is 3360.
Step 5: the absolute error is 3366 – 3360 = 6
6
Step 6: the relative error is 3366 × 100 = 0.178%

6 Floating point data representation 65


B Guided question
6 Floating point data representation

Copy out the workings and complete the answers on a separate piece of paper.
1 a Find the absolute and relative errors when the value 109.5 is represented using
8 bits for the mantissa and 4 bits for the exponent.
Step 1: find the fixed point binary representation of 109.5.
Step 2: normalise this number and therefore work out the mantissa and the
exponent.
Step 3: cut down the mantissa so that it fits into the 8 bits given in the question by
removing digits from the right-hand side.
Step 4: calculate the new value of the number in denary, using the new mantissa
and the exponent.
Step 5: find the absolute error by subtracting the new value from the true value.
absolute error
Step 6: find the relative error by using true value × 100.
b Find the absolute and relative errors when the value 109.5 is represented using
4 bits for the mantissa and 4 bits for the exponent.
Steps 1 and 2: this uses the same true value as in part a, so find the normalised
version of this from Step 2 of part a.
Step 3: this time, trim down the mantissa to fit into 4 bits.
Step 4: calculate the new value of the number in denary, using the new mantissa
and the exponent.
Step 5: find the absolute error by subtracting the new value from the true value.
absolute error
Step 6: find the relative error by using true value
× 100.

C Practice questions
2 Find the absolute and relative errors when:
a 178.56 is stored as 178
b 56 564 is stored as 56 500
c 0.0000034 is stored as 0.000003
3 Find the absolute and relative errors when the value 47.75 is represented using 6 bits
for the mantissa and 4 bits for the exponent.
4 Find the absolute and relative errors when the value 30 079 is represented using 6 bits
for the mantissa and 5 bits for the exponent.

66 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


7 Representing images, sound and
other data

Note: this Unit is assessed at AS and A-level by AQA only.

Bitmap images
A bitmap image is made up of many smaller blocks, called pixels. Each pixel is assigned
a single colour, with the computer storing a bit pattern to represent this colour. As these
single-colour pixels are so small, the human eye interprets the bitmap as a complete picture.

Figure 7.1 A bitmap image showing the individual pixels.

The resolution of a bitmap image


The resolution of a bitmap image is simply a measure of the number of pixels in an
image. This is given either as a number of megapixels (each megapixel being 1 million
pixels) or as two values separated by a multiplication sign, such as 1024 × 768. These
two values are the number of pixels in the horizontal width of the image and the number
of pixels in the vertical height. To calculate the number of pixels in the image, simply
multiply these two numbers together.

Storage requirements for a bitmap image


Once it is understood that a bitmap image stores a bit pattern for every pixel, and it
is known how many pixels are in the image, it is a short step to work out the storage
requirements for the whole image. The final piece of information that is required is the
number of bits needed for each pixel.
A black and white image could be stored using 1 bit per pixel; the single bit could be either 0
for white or 1 for black. 1 bit gives us 2 permutations (0 or 1). If we increased the bit depth to
2 bits, we now have 4 permutations (00, 01, 10 or 11) and so 2 bits would be enough to store an
image using 4 colours. Increasing the bit depth to 3 bits gives 8 permutations (000 to 111). For
a given bit depth b, there are always 2b distinct colours available.

7 Representing images, sound and other data 67


A permutation is the number of ways that a set of values can be ordered, where the
7 Representing images, sound and other data

order matters. Really, a combination lock should be called a permutation lock. The
number of permutations of a set of values of size n is n! (read ‘n factorial’). For example,
a set of 5 letters can be arranged in 5! ways (5 × 4 × 3 × 2 × 1 = 120 ways).

log ( c )
Conversely, if c colours are need to be stored then will give the number of bits
log (2)
required. If the number given by this equation is not an integer, then rounding up is
necessary to the next whole number.
Once the number of pixels in an image and the number of bits required for each pixel are both
known, these can be multiplied together to find the storage requirements for the image in bits.
This can then be converted to the required units using the methods described in Unit 3.

Metadata
Alongside the raw data about each pixel, some bitmap image formats store information
about the image. This will typically include the resolution and bit depth, but some file
formats such as JPG can also store information about the author, the hardware used to
create the picture or even geographical tagging information. This data about the image is
called metadata and will take up a small amount of additional storage space.

A Worked examples
a A bitmap image is 1500 × 1200 in size. Calculate the resolution of the image in megapixels.
Step 1: calculate the number of pixels in the image by multiplying 1500 × 1200 = 1 800 000 pixels.
Step 2: each megapixel is 1 million pixels, so divide 1 800 000 ÷ 1 000 000 = 1.8.
So the resolution is 1.8 megapixels.
b A bitmap image has resolution 2048 × 512 and contains 23 distinct colours. Calculate the file
size of the image in kilobytes.
Step 1: calculate the number of pixels in the image by multiplying 2048 × 512 = 1 048 576 pixels.
log ( 23)
Step 2: 23 distinct colours needs bits per pixel = 4.524.
log (2)
Step 3: round this up to give the actual number of bits needed per pixel = 5 bits.
Step 4: multiply the number of pixels by the bits per pixel = 1 048 576 × 5 = 5 242 880 bits.
Step 5: convert this to kilobytes:
5 242 880 ÷ 8 = 655 360 bytes
655 360 ÷ 1024 = 640 kilobytes
So the file size is 640 kilobytes.

68 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


B Guided questions

7 Representing images, sound and other data


Copy out the workings and complete the answers on a separate piece of paper.
1 A bitmap image stores each pixel using 8 bits. Calculate the maximum number
of distinct colours available to use in this image.
■ Remember, the formula 2b tells us the number of permutations of the binary digits
that are available when using b bits.
■ Each colour needs to be represented by its own unique binary bit pattern.
■ Use the formula 2b, where b is the number of bits to be used.
2 A bitmap image uses 6 bits per pixel and has a resolution of 500 × 200. Calculate
the file size of the image in kilobytes, to 1 decimal place.
Step 1: calculate the number of pixels in the image: 500 × 200 =
Step 2: multiply the number of pixels × 6 bits per pixel =
Step 3: convert to bytes by dividing by 8.
Step 4: convert to kilobytes by dividing by 1024.
Step 5: round your answer to 1 decimal place.
3 A bitmap image with resolution 512 × 512 is stored in a file that is 384 kB in size.
Calculate the maximum number of distinct colours that this image can use.
Step 1: calculate the number of pixels in the image: 512 × 512 =
Step 2: calculate the file size in bits = 384 kB × 1024 = bytes × 8 =
Step 3: calculate the number of bits allocated per pixel. To do this, divide the number
of bits needed by the number of pixels in the image.
Step 4: find the maximum number of distinct colours by using the formula 2b, where
b is the number of bits found in Step 3.
4 A bitmap image has resolution 800 × 800 and contains 14 distinct colours. Calculate
the file size of the image in kilobytes, rounding to the nearest whole number.
Step 1: calculate the number of pixels in the image by multiplying
800 × 800 =
log (14 )
Step 2: 14 distinct colours needs bits per pixel =
log (2)
Step 3: round this up to give the actual number of bits needed per pixel.
Step 4: multiply the number of pixels (Step 1) by the bits per pixel (Step 3).
Step 5: convert this to kilobytes.
Step 6: round to the nearest whole number.

C Practice questions
5 a A bitmap image has resolution 1000 × 400. Calculate the resolution in megapixels.
b Each pixel in the image is stored using 16 bits. Calculate the file size in bytes.
6 a A bitmap image with resolution 2000 × 5000 uses 400 distinct colours. Calculate
the size of the file in megabytes.

7 Representing images, sound and other data 69


b The image’s resolution is increased to 5000 × 5000. Calculate the increase in file
7 Representing images, sound and other data

size from part a in megabytes, to 1 decimal place.


c Calculate the change in file size from part b if the number of colours is increased to:
i 500
ii 600
7 A bitmap image with resolution 512 × 512 is stored in a file that is 384 kB in size.
Calculate the maximum number of distinct colours that this image can use.
8 Calculate the file size of the following bitmap files. Give your answers to 1 decimal
place and use the most appropriate units.
a Resolution 100 × 100, 4 bits per pixel
b Resolution 256 × 800, 6 bits per pixel
c Resolution 900 × 2150, 16 bits per pixel with 100 kilobytes of metadata

Sound samples
A sound wave is analogue, continuous data. In order for a computer to store a
representation of a sound wave, regular samples of the height of the waveform need to be
taken which are then converted to binary and stored.

Figure 7.2 Sampling at a low sample rate.

Figure 7.3 Sampling at a higher sample rate.

Calculating the size of a sound file.


To calculate the size of a sound file, three pieces of information are needed: the length
of the sound file (in seconds), the sample rate (this is the number of samples taken
per second measured in hertz, where 1 Hz is one sample per second) and the sample
resolution (the number of bits used to store each sample).

70 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


To find the file size in bits, use the formula

7 Representing images, sound and other data


length in seconds × sample rate × sample resolution
This formula can also be rearranged using standard algebraic rules to find any of the
other items if needed.

The quality of the sound file depends on both the sample resolution and the sample
rate. The higher that both of these are, the better the quality of the audio. As an
example, telephone calls use a resolution of 8 bits and a sample rate of 11 kHz. Music
CDs use 16 bits and 44 kHz.

A Worked examples
a A 30 second sound file has a sample rate of 44 000 Hz using 16 bits per sample. Calculate the file
size in bytes.
■ Remember that there are 8 bits in a byte.
■ A bit is a binary digit, a 1 or a 0.
Step 1: multiply the length (in seconds) by the sample rate (in Hz) and multiply this by the sample
resolution (in bits). This would be 30 × 44 000 × 16 = 21 120 000 bits.
Step 2: divide by 8 to convert to bytes = 2 640 000 bytes.
b A voice recording uses 8 bits per sample and a sample rate of 8 kHz (note: 1 kHz = 1000 Hz). The
recording is stored in a file that is 50 kilobytes in size. Calculate the length of the recording, in
seconds.
Step 1: rearrange the formula
size = length × rate × resolution
to give
size (in bits)
length = rate resolution
×
Step 2: calculate the file size in bits by multiplying by 1024 and then by 8.
50 × 1024 × 8 = 409 600 bits
Step 3: use the formula from Step 1.
409 600 409 600
length = = = 6.4 seconds
8000 × 8 64 000

B Guided questions
Copy out the workings and complete the answers on a separate piece of paper.
1 An audio file is recorded using a resolution of 16 bits and a sample rate of 48 kHz.
The audio file is 90 seconds long. Calculate the size of the file in megabytes,
giving your answer to 3 decimal places.
Step 1: calculate number of bits: 90 × 16 × 48 000 =
Step 2: convert this to megabytes by dividing by 8 (to obtain bytes), then dividing by
1024 (to obtain kilobytes) then dividing by 1024 again (to obtain megabytes).
Step 3: round to three decimal places.

7 Representing images, sound and other data 71


2 A sound file is 5 minutes long and is recorded using 12 bits per sample and a
7 Representing images, sound and other data

sample rate of 44 kHz. Calculate the size of the file in megabytes, rounding to the
nearest megabyte.
Step 1: calculate the number of seconds in 5 minutes.
Step 2: use the answer from Step 1 together with the sample resolution (12) and the
sample rate (44 000) to calculate the file size in bits.
Step 3: convert this to megabytes.
Step 4: round to the nearest megabyte.
3 A band records its latest song using a resolution of 16 bits and a sample rate of
44 kHz. It records separate tracks for the singer, the guitar player, the bass player
and the drummer. Each track is 3 minutes long. Calculate the total size of the
files recorded in megabytes, rounding to the nearest megabyte.
Step 1: use the formula given at the start of this section to calculate the file size, in
bits, for one of the audio tracks (remember to use seconds not minutes!).
Step 2: multiply this by 4 (as there are 4 tracks recorded).
Step 3: convert to megabytes and round as needed.

C Practice questions
4 Calculate the file size of the following sound files. Give your answers to 3 decimal
places, using the most appropriate unit.
a Length = 15 seconds, sample resolution = 8 bits, sample rate = 11 500 Hz
b Length = 90 seconds, sample resolution = 16 bits, sample rate = 32 kHz
c Length = 2.5 minutes, sample resolution = 16 bits, sample rate = 44.8 kHz
d Length = 1 hour, sample resolution = 8 bits, sample rate = 8 kHz
5 An audio recording uses 24 bits per sample and a sample rate of 48 kHz. The
recording is stored in a file that is 10 megabytes in size. Calculate the length of the
recording, in seconds.
6 A sound file is 525 kilobytes in size, has a length of 38.4 seconds and has been
recorded using a resolution of 8 bits per sample. Calculate the sample rate used during
the recording.
7 A student records the evening news from the radio each day. Each news broadcast
is exactly 5 minutes long and the student records it using a resolution of 16 bits
and a sample rate of 44 kHz. The files are then uploaded to a website with a limit
of 1 gigabyte on storage. How many broadcasts can the student store in the space
available?

72 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


8 Boolean algebra

Logic gates
Almost all modern computers use a binary system to represent data, with two
outputs (1 or 0, representing True or False) available for every proposition. A logical
proposition is a statement which is either True or False. For example, the output in a
computer game as to whether a player has collided with an enemy is either 1 (True,
the player and enemy have collided) or 0 (False, they have not collided). There are no
other possible outputs.
Logic gates allow the computer to make decisions based on joining these propositions
together, with three basic gates used: AND, OR and NOT. For example, we could say
that the game is over if a player collides with an enemy AND their energy level is low.
In this case, both of the two propositions would need to be true (output 1) for the ‘game
over’ output to be 1. If either (or both) output is 0 then the ‘game over’ output will be 0.
The outputs for two propositions connected with an AND gate are shown in Table 8.1. This
is called a truth table.

Table 8.1
A: Collided with enemy B: Energy level low Game over (A AND B)
0 0 0
1 0 0
0 1 0
1 1 1

The OR gate is similar, but the output is 1 if the output of either (or both) of the
propositions is 1. NOT is slightly different in that it only takes one input and simply
inverts this. If A = 1 then (NOT A) = 0 and vice versa.
Three slightly more complex gates that can be used are NAND, NOR and XOR. These
are explained in Table 8.2.

Table 8.2
Logic gate Explanation
NAND This is the same as AND, but with the output inverted.
A NAND B is the same as NOT(A AND B).
NOR This is the same as OR, but with the output inverted.
A NOR B is the same as NOT(A OR B).
XOR This is known as an ‘eXclusive OR’ gate. The output is 1 if either
one, but not both, of the inputs is 1. If both inputs are 1 or both inputs
are 0 then the output will be 0. This logic gate is commonly used to
decide if two inputs are different.

8 Boolean algebra 73
A Worked example
8 Boolean algebra

Complete the truth table for the following expressions.


i A XOR B

The XOR gate produces a 1 output if either, but not both, of the inputs are 1. The truth table is
therefore:

Table 8.3
A B A XOR B
0 0 0
1 0 1
0 1 1
1 1 0

■ A truth table simply shows all possible permutations of 1 and 0 values for the input variables.
■ In this case, because there are two inputs, there are four permutations as shown above.
■ If there were three inputs, there would be nine permutations and therefore nine rows in the
truth table.
ii NOT (A OR B)
Just like in normal algebra, we work on the contents of the brackets first. The truth table for A OR B
would be:

Table 8.4
A B A OR B
0 0 0
1 0 1
0 1 1
1 1 1

The NOT outside the brackets simply inverts the output, so every 0 output turns to 1 and every
1 output turns to 0. The final truth table is therefore:

Table 8.5
A B A OR B NOT (A OR B)
0 0 0 1
1 0 1 0
0 1 1 0
1 1 1 0

■ Once you are confident with constructing truth tables, you do not need to show the intermediate
steps unless the question specifically asks for it.
■ NOT (A OR B) is equivalent to A NOR B.

74 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


B Guided question

8  Boolean algebra
Copy out the workings and complete the answers on a separate piece of paper.
1 Create truth tables for each of the following expressions.
a A OR B
Step 1: create a truth table with all four possible permutations of A and B, with
a column for the output. This is shown below.

Table 8.6
A B A OR B
0 0
1 0
0 1
1 1

Step 2: the OR connective gives a 1 output when either of A or B is 1. The output is


0 only if A and B are both 0. Complete the table above.
b A NAND (NOT B)
Step 1: create a truth table with all four possible permutations of A and B.
Step 2: the brackets should always be evaluated first, so work out the output for
NOT B for each row in the truth table.

Table 8.7
A B NOT B
0 0
1 0
0 1
1 1

Step 3: now use the logic connective NAND to join together the columns A
and NOT B (you can ignore the B column at this point). Remember, NAND is
equivalent to AND with the output reversed. Complete the table below.

Table 8.8
A B NOT B A NAND (NOT B)
0 0
1 0
0 1
1 1

c (A AND B) OR C
Step 1: create a truth table with all nine possible permutations of A, B and C.
Step 2: evaluate the brackets first, so evaluate the expression A AND B for each row in
the truth table. You may wish to add the output as a new column into the truth table.
Step 3: now use OR to connect together the outputs from Step 2 with the values in
the C column in the truth table.

8 Boolean algebra 75
C Practice question
8 Boolean algebra

2 Create truth tables for each of the following expressions.


a A AND NOT B
b A NAND B
c NOT(A NOR B)
d NOT(A XOR (B AND C))
e A OR B OR C

Boolean algebra
Boolean algebra is a formalised way of representing logical statements. It was introduced
by George Boole, an English mathematician, in his book The Mathematical Analysis of
Logic (1847).
The basic logic gate operations of AND, OR, XOR and NOT are replaced with symbols.
The most common of these symbols are shown in Table 8.9.
Table 8.9 Boolean logic symbols
Logic operation Symbol Example
AND ∧ A∧B (A AND B)
OR ∨ A∨B (A OR B)
NOT ¬ ¬ A (NOT A)
XOR ⊕ A⊕B (A XOR B)
Some other resources or questions may use different symbols (a dot for AND, a plus sign
for OR and a bar over the text for NOT are common), but the symbols in the table above
will be consistently used in this book.

A Worked examples
a A and B are two inputs that are joined together by a NAND gate to give output C. Give the
Boolean algebraic expression for this arrangement.
Step 1: there is no symbol for NAND, but recognise that a NAND gate is equivalent to NOT(AND).
Step 2: replace the NOT and AND with symbols. The Boolean expression is therefore C = ¬(A∧B).
b Create a truth table for the expression A ∨ ¬B.
Table 8.10a
Step 1: create an outline of a truth table showing all four A B A∨¬B
permutations of A and B. This has been done here. 0 0
Step 2: decide what symbols are used in the question. In this 1 0
case, A∨ ¬B is A OR NOT B. 0 1
1 1

Step 3: for each row in the truth table, evaluate this expression Table 8.10b
with the given values of A and B. For example, the first row A B A∨¬B
has A = 0 and B = 0. NOT B would be 1 and so the expression 0 0 1
is 0 OR 1, giving an output of 1. 1 0 1
0 1 0
1 1 1

76 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


B Guided questions

8  Boolean algebra
Copy out the workings and complete the answers on a separate piece of paper.
1 Let W = ‘I will take a taxi’, X = ‘it is raining’, Y = ‘I have money in my pocket’ and
Z = ‘I am late’. Write the following statement using Boolean logic symbols and the
above statements: ‘I will take a taxi if it is raining or I am late, but only if I have
money in my pocket’.
Step 1: decide which of W, X, Y or Z above is the output.
Step 2: for the remaining three logic statements, any that must all happen should be
joined together with the symbol for AND. If there is a choice of one or the other, then
join these together with the symbol for OR.
Step 3: use brackets to clarify the order for evaluation if necessary.
2 A and B are two inputs that are joined together with an XOR gate. The output
of this is then joined to C with an AND gate to give output X. Give the Boolean
algebraic expression for this arrangement.
Step 1: the output is X, so start off the expression with X =
Step 2: after this, use the XOR symbol to join together A and B.
Step 3: as the output of this is used in the next expression, add brackets around your
answer to Step 2.
Step 4: use the AND symbol to join this to C.
3 Create a truth table for the expression A⊕ ¬B.
Step 1: create an outline of a truth table showing all four permutations of A and B.

Table 8.11
A B A⊕ ¬ B
0 0
1 0
0 1
1 1

Step 2: decide what symbols are used in the question, translating these into AND, OR,
XOR or NOT.
Step 3: if you need to, create extra columns in the table to work out intermediate steps.
However, this may not be necessary depending on how confident you feel.
Step 4: evaluate each row in the truth table according to logic rules. Fill in the output.

C Practice questions
4 Write each of the following logic gate arrangements as a Boolean expression.
a The input A is connected to a NOT gate. The output of this is joined to B with an
AND gate. The output of this is connected to another NOT gate, giving output C.
b Two inputs A and B are connected to a NOR gate. Two more inputs, C and D are
connected to an XOR gate. The output of both of these gates is connected to an
AND gate, giving output E.

8 Boolean algebra 77
5 A student has to have good attendance and hand in all of their homework in order to
8 Boolean algebra

be eligible to pass a course. In addition, they must either score 50%+ on a test or score
70%+ on a piece of coursework.
The logic statement A = (B ∧ C) ∧ (D ∨ E) represents these course criteria.
a If A is defined as ‘the student passes the course’, give definitions for each of B, C,
D and E.
b Create a truth table for this logic statement.
6 Imogen investigates a logic system and defines the output using the expression
¬ (A ∧ B). Another student suggests that the expression should instead be ¬A ∨ ¬B.
Imogen states that both expressions will produce the same output.
Investigate whether Imogen is correct or not by creating and comparing truth tables
for both expressions.

Boolean identities and De Morgan’s laws


Boolean identities are equivalencies that are true for every possible set of input
values. By knowing these identities, we can simplify logic statements. For example, a
complicated circuit made up of 20 logic gates may be able to be simplified to only 5 or 6
gates, therefore making a circuit cheaper to manufacture. Each of the identities listed in
Table 8.12 can be treated as straight replacements.

Table 8.12 Boolean identities


Equivalences Further explanation
1 ∧ A = A True AND A is the equivalent of just A. Likewise, False OR A is
0 ∨ A = A the equivalent of just A. These are the identity laws.
¬¬A = A NOT NOT A is the equivalent of A; if you invert something twice,
you return to the original value. This is the double complement law.
0 ∧ A = 0 False AND A is always False. True OR A is always True. These
1 ∨ A = 1 are the dominance laws.
A ∧ A = A A AND A is the equivalent of just A. A OR A is also the
A ∨ A = A equivalent of just A. These are the idempotence laws.
A ∧ ¬A = 0 A AND NOT A is always False. A OR NOT A is always True.
A ∨ ¬A = 1 These are the inverse laws.
A ∧ B = B ∧ A A AND B is exactly the same as B AND A. Likewise, A OR B is
A ∨ B = B ∨ A exactly the same as B OR A. The order of two inputs joined by a
logic gate does not matter. These are the commutative laws.
A ∧(A ∨ B) = A A AND (A OR B) is equivalent to just A. Likewise, A OR (A AND
A ∨ (A ∧ B) = A B) is also equivalent to just A. These are the absorption laws.
(A ∧ B) ∧ C = A ∧ (B ∧ C) When three inputs are joined by two AND gates, the order that they
(A ∨ B) ∨ C = A ∨ (B ∨ C) are joined in does not matter. Likewise, the order of three inputs
joined by OR gates does not matter. These are the associative laws.
A ∧ (B ∨ C) = (A ∧ B) This identity is similar to the way multiplying out brackets works.
∨ (A ∧ C) 5 × (6 + 2) is the same as (5 × 6)+(5 × 2). Be careful to ensure that
A ∨ (B ∧ C) = (A ∨ B) ∧ the correct Boolean symbols are used as it is easy to get these
(A ∨ C) wrong. These are the distributive laws.

78 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


Most of the above identities fit in with common sense when they are turned into sentence

8  Boolean algebra
format. For example, the idempotence laws say that I can reduce ‘I will go to bed if I am
tired or I am tired’ down to just ‘I will go to bed if I am tired’. The inverse laws say that
evaluating ‘it is the weekend and it is not the weekend’ will always give a False output.
One set of laws that is perhaps not so linked to common sense or basic mathematics is
De Morgan’s laws, named after the nineteenth-century British mathematician Augustus
De Morgan. These are listed in the Table 8.13.

Table 8.13 De Morgan’s laws


Equivalences Further explanation
¬ (A ∧ B) = (¬A) ∨ (¬B) NOT(A AND B) is equivalent to (NOT A) OR (NOT B).
¬ (A ∨ B) = (¬A) ∧ (¬B) Likewise, NOT(A OR B) is equivalent to (NOT A) AND
(NOT B). Notice that when expanding each statement into two
brackets, the gate used changes.

A Worked examples
a Simplify the expression A ∨ (A ∧ B) ∨ ¬A.
Step 1: use the absorption laws to replace A ∨ (A ∧ B) with A.
Step 2: the expression is now A ∨ ¬A.
Step 3: the inverse law states that A ∨ ¬A = 1. The expression will therefore always output 1.
b Simply the expression (¬A ∧ ¬B).
Step 1: use De Morgan’s law to replace ¬ (A ∧ ¬B) with (¬A) ∨ (¬¬B).
Step 2: use the double complement rule to replace ¬¬B with B.
Step 3: the simplified expression is therefore (¬A) ∨ B.

B Guided questions
Copy out the workings and complete the answers on a separate piece of paper.
1 Simplify the expression 0 ∨ (1 ∧ A).
Step 1: use the identity laws to simplify the contents of the brackets.
Step 2: decide whether the resulting expression can be simplified any further.
2 A logic circuit manufacturer has a limited stock of OR gates. Rewrite the
expression ¬ ((A ∨ A) ∨ B) so that no OR gates are used.
Step 1: use an appropriate law to simplify (A ∨ A).
Step 2: use De Morgan’s laws to rewrite the resulting expression without using ∨.
3 Simplify the expression B ∨ ¬ (A ∧ B).
Step 1: apply De Morgan’s laws to the expression where appropriate.
Step 2: another law can be used to simplify this even further. You may need to use the
associative laws to rearrange the order of the equation so that this becomes obvious.
Step 3: write down the new simplified version of the expression.

8 Boolean algebra 79
C Practice questions
8 Boolean algebra

4 Identify which Boolean identities can be linked to each sentence below:


a Fish AND chips is the same meal as chips AND fish.
b ‘I do not want to not go out’ means that I will go out.
c An AND gate that has one input that is always False will always give a False
output.
5 Rewrite the expression ¬ (A ∧ B) ∨ (C ∧ C) so that no AND gates are used.
6 A logic system is defined by the expression ¬¬ ((A ∧ ¬A) ∨ B) ∨ C.
a Simplify this Boolean expression.
b State whether the expression (A ∨ B) ∧ (B ∧ B) ∧ C is equivalent to your answer
from part a.

80 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


9 Vectors

Note: this Unit is assessed at A-level by AQA only.

Vector representation
A vector is an element that can be represented and implemented in a variety of ways, for
example, points in space, lists and mathematical functions.

Arrows
((
A vector can be written as A = ( r , θ ) or A = r . This vector has two
θ
y
12
dimensions: the first (r) is the size of it, and the second (θ) is the 11
10
direction of it. 9
8
In Figure 9.1 the arrow represents a vector. If we call this arrow 7
6
vector A, then the dimensions will be its position on the x and y axis. 5
4
The x-coordinate is 7, the y-coordinate is 10. This vector is written as 3
7  2
A = (7, 10) or A =   . This can be extended into three-dimensions 1
10
0
with a z-axis, e.g. A = (2, 3, 4). 0 1 2 3 4 5 6 7 8 9 10 11 12 x

Figure 9.1
Data structure
A vector can be represented as an array or list. Arrays can be drawn as a table. An
example is shown in Table 9.1.

Table 9.1 Ages of ten people

Index 0 1 2 3 4 5 6 7 8 9
Data 22 13 56 74 11 5 6 89 51 21

The index is the position of the data, starting traditionally at 0 (this may differ if you are
writing an array in a programming language, because some languages start counting at 0,
others at 1).
This type of vector can be written as a dictionary structure. Table 9.1 could be written as:
{0:22, 1:13, 2:56, 3:74, 4:11, 5:5, 6:6, 7:89, 8:51, 9:21}

Function
A vector can also be represented as a mathematical function, where an input is mapped
to an output in the format F : S → R where:
■ F represents the function.
■ S represents the set of values the function is applied to.
■ R is the output of the function.

9 Vectors 81
An example of a function would be f (x) = 10x where:
9 Vectors

■ f is the function.
■ x is the set of values the function is applied to.
■ 10x is the output of the function.

A Worked examples
 
a Draw a graph to represent the vector A =  2  .
3 
Step 1: draw the axes.
y

Figure 9.2

Step 2: add the figures on the axes. The numbers on the horizontal axis need to go to at least 2, the
numbers on the vertical axis need to go to at least 3.
y
12
11
10
9
8
7
6
5
4
3
2
1
0
0 1 2 3 4 5 6 7 8 9 10 11 12 x

Figure 9.3

Step 3: draw the arrow representing the vector. It should start from (0, 0), with the head at (2, 3).
y
12
11
10
9
8
7
6
5
4
3
2
1
0
0 1 2 3 4 5 6 7 8 9 10 11 12 x

Figure 9.4

82 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


9 Vectors
b Table 9.2 shows the elements in an array.

Table 9.2
Index 0 1 2 3
Data 9 14 2 3

Write this array in a dictionary structure.


Start the dictionary with {, then follow the pattern index:value, index:value etc. ending with }.
{0:9, 1:14, 2:2, 3:3}

B Guided questions
Copy out the workings and complete the answers on a separate piece of paper.
10 
1 Draw a graph to represent the vector A =   .
1
Step 1: draw the axes.
Step 2: add the figures on the axes. The x-axis needs to go to at least 10, the y-axis
needs to go to at least 1.
Step 3: draw the arrow representing the vector, starting from (0, 0) with the head at
(10, 1).
2 Table 9.3 shows the elements in an array.
Table 9.3
Index 0 1 2 3
Data 4 3 2 1

Write this vector in a dictionary structure.


Follow the pattern {index:value, index:value, …}

C Practice questions
 3
3 Draw a graph to represent the vector A = 12 .
 
2
4 Draw a graph to represent the vector A = 9  .
 
5 Table 9.4 shows the elements in an array.

Table 9.4
Index 0 1 2 3 4 5
Data 56 42 12 1 55 12

Write this vector in a dictionary structure.


6 Table 9.5 shows the elements in an array.

Table 9.5
Index 0 1 2 3 4 5 6 7
Data 7 6 5 4 3 2 1 0

Write this vector in a dictionary structure.

9 Vectors 83
Vector addition
9 Vectors

Addition can take place on two (or more) vectors, when they have the same number of
dimensions.
The x-components are added, the y-components are added and any further components
(e.g. z) are added.

A Worked examples
2 5
a Add the two vectors A =   and B =   .
3 6
Step 1: add the x-components: 2 + 5 = 7.
Step 2: add the y-components: 3 + 6 = 9.
 
Step 3: write the new x- and y-components: A + B =  7 
9 
5  9  10 
     
b Add the three vectors A = 10  , B= 5  and c =  2 .
6  4  1
     
Step 1: add the x-components: 5 + 9 + 10 = 24.
Step 2: add the y-components: 10 + 5 + 2 = 17.
Step 3: add the z-components: 6 + 4 + 1 = 11.
 24 
 
Step 4: write the new x-, y- and z-components: A + B + C =  17  .
 11 
 

B Guided questions
Copy out the workings and complete the answers on a separate piece of paper.
10  3
1 Add the two vectors A =   and B =   .
 2 4

Step 1: add the x-components.


Step 2: add the y-components.
Step 3: write the new x- and y-components.
9   20   9
     
2 Add the three vectors A = 12  , B=  30  and C = 9  .
2   40  1 
     

Step 1: add the x-components.


Step 2: add the y-components.
Step 3: add the z-components.
Step 4: write the new x-, y- and z-components.

84 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


C Practice questions

9 Vectors
1  8  
3 Add the two vectors A =   and B =   .
3 5
  97  
4 Add the two vectors A =  55  and B =   .
12   12 

12   
5 Add the two vectors A =   and B = 13 .
7 6
10   20  19 
     
6 Add the three vectors A = 11  , B=  21  and C = 18  .
12  4  17 
     
8   22   43 
     
7 Add the three vectors A = 77  , B= 65  and C =  90  .
3  2  102 
     
54  1  91 
     
8 Add the three vectors A = 13  , B = 3  and C = 56  .
16  2  12 
     

Scalar vector multiplication


A vector can be multiplied using a number called a scalar. This is a number that you then
multiply each component of the vector by to produce a new vector.
The new vector is a scaled version of the original. If you multiply by a scalar of 3, the
new vector will be 3 times the size (magnitude) of the original vector. The direction on
the graph will not change. The line will be longer.

A Worked examples
4
a Multiply the vector A =   by the scalar 3.
6
Step 1: multiply the x-component by 3: 4 × 3 = 12.
Step 2: multiply the y-component by 3: 6 × 3 = 18.
12  
Step 3: write the new vector with a different letter: B =   .
18 
2 
 
b Multiply the vector A = 3  by the scalar 5.
4 
 
Step 1: multiply the x-component by 5: 2 × 5 = 10.
Step 2: multiply the y-component by 5: 3 × 5 = 15.
Step 3: multiply the z-component by 5: 4 × 5 = 20.
10 
 
Step 4: write the new vector with a different letter: B = 15  .
 20 
 

9 Vectors 85
B Guided questions
9 Vectors

Copy out the workings and complete the answers on a separate piece of paper.
12
1 Multiply the vector A =   by the scalar 10.
4
Step 1: multiply the x-component by 10.
Step 2: multiply the y-component by 10.
Step 3: write the new vector with a different letter.
100 
 
2 Multiply the vector A = 101  by the scalar 2.
102 
 
Step 1: multiply the x-component by 2.
Step 2: multiply the y-component by 2.
Step 3: multiply the z-component by 2.
Step 4: write the new vector with a different letter.

C Practice questions
 
3 Multiply the vector A =  9  by the scalar 4.
5
 
4 Multiply the vector A = 12  by the scalar 2.
3
 
5 Multiply the vector A =  9  by the scalar 5.
14 
6 
 
6 Multiply the vector A =  2  by the scalar 6.
10 
 
5 
 
7 Multiply the vector A =  7  by the scalar 3.
12 
 
50 
 
8 Multiply the vector 60  by the scalar 8.
70 
 

Dot product of two vectors


A dot product involves multiplying two vectors together. The result of a dot product is a
number. The x-components from both vectors are multiplied together, and added to the
product of the y-value from both vectors. If you have a third dimension, then the z-values
are multiplied together and added to this number.
The dot product may be represented as A . B, where A and B are the two vectors being
multiplied.

86 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


A Worked examples

9 Vectors
2 12
a Calculate the result of A . B where A =   and B =   .
4 4
Step 1: multiply the x-values together: 2 × 12 = 24.

Step 2: multiply the y-values together: 4 × 4 = 16.

Step 3: add the results together: 24 + 16 = 40.


5  10 
   
b Calculate the result of A . B where A =  4  and B =  2  .
3  1 
   
Step 1: multiply the x-values together: 5 × 10 = 50.

Step 2: multiply the y-values together: 4 × 2 = 8.

Step 3: multiply the z-values together: 3 × 1 = 3.

Step 4: add the results together: 50 + 8 + 3 = 61.

B Guided questions
Copy out the workings and complete the answers on a separate piece of paper.
5  2 
1 Calculate the result of A . B where A =   and B =   .
6  3 
Step 1: multiply the x-values together.
Step 2: multiply the y-values together.
Step 3: add the results together.
12  5
   
2 Calculate the result of A . B where A =  30  and B =  9  .
2  10 
   
Step 1: multiply the x-values together.
Step 2: multiply the y-values together.
Step 3: multiply the z-values together.
Step 4: add the results together.

C Practice questions
   
3 Calculate the result of A . B where A =  1  and B =  5  .
3  12 

4   
Calculate the result of A . B where A =   and B =   .
19
4
4  23 
   
5 Calculate the result of A . B where A =  2  and B =  71  .
1  65 
8  12 
   
6 Calculate the result of A . B where A = 6  and B =  3  .
2  4 
   

9 Vectors 87
2  10 
9 Vectors

   
7 Calculate the result of A . B where A = 3  and B = 11  .
4  12 
   
5  6 
   
8 Calculate the result of A . B where A =  2  and B = 10  .
2   20 
   

Convex combination of two vectors


A convex hull is the vector space made up by two vectors. In Figure 9.5, for example,
 2  10 
A=  , B= .
 10   3
These can be represented as arrows. In Figure 9.5, y
12
A is red, B is blue. 11
10
9
8
7
6
5
4
3
2
1
0
0 1 2 3 4 5 6 7 8 9 10 11 12 x
Figure 9.5

The convex hull is the space created between y


12
these arrows. In Figure 9.6, this area has been 11
shaded. 10
9
8
7
6
5
4
3
2
1
0
0 1 2 3 4 5 6 7 8 9 10 11 12 x
Figure 9.6

A convex combination produces a vector that is y


12
within this hull. In Figure 9.7, the green arrow 11
represents the vector C = (6, 4). This is within 10
9
the hull therefore it is a convex combination. 8
7
6
5
4
3
2
1
0
0 1 2 3 4 5 6 7 8 9 10 11 12 x
Figure 9.7

88 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


In Figure 9.8, the orange arrow represents the vector y

9 Vectors
12
C = (10, 10). This arrow is outside the hull therefore 11
it is not a convex combination. 10
9
There is a formula that states what the vectors 8
7
must be multiplied by in order to gain a convex 6
combination. 5
4
D = αA + βB 3
2
A and B are the two vectors. α and β are the 1
0
numbers that the vectors will be multiplied by. 0 1 2 3 4 5 6 7 8 9 10 11 12 x
These must both be >0, and α + β = 1. Figure 9.8

A Worked examples
   
a A vector is represented by D
D = 0.2 × 12  + 0.8 × 2  .
3  8 
12  2 
Is D a convex combination of A =   and B =   ?
3 8 

Step 1: check that α and β are both > 0. TRUE

Step 2: check that α + β = 1: 0.2 + 0.8 = 1 TRUE

This means D is a convex combination.

2   7
b Two vectors are represented as A =   and B =   . A combination of these is
4  10 
D = 0.4 A + 0.8 B .
Is D a convex combination of A and B?

Step 1: check that α and β are both > 0. TRUE

Step 2: check that α + β = 1: 0.4 + 0.8 = 1.2 FALSE

This means D is not a convex combination.

B Guided questions
Copy out the workings and complete the answers on a separate piece of paper.
12  2 
1 Two vectors are represented as A =   and B =   . A combination of these is
3 1 
D = – 0.13A + 0.95B.

Is D a convex combination of A and B?


Step 1: check that α and β are both > 0.
Step 2: check that α + β = 1
If Step 1 and Step 2 are both True, D is a convex combination, otherwise it is not.

9 Vectors 89
 29  12 
9 Vectors

   
2 Two vectors are represented as A = 100  and B =  6  . A combination of these is
 20  9
D = 0.5A + 0.6B.    
Is D a convex combination of A and B?
Step 1: check that α and β are both > 0.
Step 2: check that α + β = 1
If Step 1 and 2 are both True, D is a convex combination, otherwise it is not.

C Practice questions
7  12 
3 Two vectors are represented as A =   and B =   . A combination of these is
8  3
D = 0.2A + 0.8B. Is D a convex combination of A and B?
100   99 
   
4 Two vectors are represented as A = 101  and B = 100  . A combination of these is
102  101 
   
D = – 0.123A + 0.99B. Is D a convex combination of A and B?
4 2
   
5 Two vectors are represented as A = 10  and B = 7  . A combination of these is
15  3 
   
D = – 0.8A + 0.2B. Is D a convex combination of A and B?
13  5 
6 Two vectors are represented as A =   and B =   . A combination of these is
14  4 

D = 0.33A + 0.67B. Is D a convex combination of A and B?


12  32 
   
7 Two vectors are represented as A = 66  and B = 33  . A combination of these is
98  34 
   
D = 1A + 0B. Is D a convex combination of A and B?

90 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


10 Big-O notation and complexity
of algorithms

Functions
A function is a mathematical concept that takes an input set of values (called the domain)
and maps them to elements in another set (called the co-domain). Each element of the
domain is related to exactly one (and only one) element of the co-domain. This means
that each input has exactly one output, but the same output can be produced from
multiple different inputs.

Domain Co-domain

f(x) = 2x 1
2
1
3
2
4
3
5
6

Figure 10.1 Elements of a domain mapping to elements of the co-domain.

A very simple function would be one that multiplies the input value by 2, defined by
f(x) = 2x, shown in Figure 10.1. In this case, each element of the input set {1, 2, 3} would
be mapped to the elements of the output set {2, 4, 6}, which are all drawn from the
domain  . This is a one-to-one mapping as each input element maps to a unique output
element.
However, suppose a function took an input string and worked out the number of ways the
letters in a word could be arranged. In this case, the input value ‘cat’ could be arranged
in 6 ways and so ‘cat’ maps to 6. However, the letters in ‘dog’ can also be arranged in 6
ways and so both ‘cat’ and ‘dog’ map to 6. This is known as a many-to-one function as
many input values can map to the same output value. A one-to-many function is not valid
as it allows the same input to produce multiple different outputs.

Types of functions
Functions can be divided into different types based on the calculation that is used to
transform the input value to the output value. Table 10.1 shows the types of functions that
are covered in the AS and A-level computer science specifications.

10 Big-O notation and complexity of algorithms 91


Table 10.1
10 Big-O notation and complexity of algorithms

Type of function Example and explanation


Linear function A function where the output, if graphed, would be a straight line.
For example, f(x) = 2x and f(x) = 7x + 1 are both linear functions.
Polynomial function A function where the calculation to produce the output includes
raising the input value to a power (such as quadratic x2 and
cubic x3). For example, f(x) = 5x2 and f(x) = 3x3 + 2x2 – x are both
polynomial functions.
Exponential function A function where the input value is used as the power to raise
to. For example, f(x) = 3x and f(x) = 12x + 2x + 3 are both
exponential functions.
Logarithmic function A function involving the calculation of a logarithm of the input
value to a given base (where the base cannot be 1). For example,
f(x) = log2(x) and f(x) = log10(x) + 2x + 7 are both logarithmic
functions.

Functions in programming
Functions are commonly defined when creating computer programs using a high-level
language. For example, the mathematical function f(x) = 2x + 7 can be defined in Python
using the following code:
def myfunc(x) :
return (2*x) + 7
A programmer could then pass a value (such as 9) into the function by using the code
myfunc(9), which would return the value 25. This function would be a linear function.

A Worked examples
a For the function f(x) = 3x2 + x, give the set of output values if the input set = {5, 10, 20}.
Step 1: take the first input value (5).
Step 2: replace x in the equation 3x2 + x with 5, giving 3 × 52 + 5.
Step 3: calculate the output value, remembering that BIDMAS means that powers are calculated
first, then multiplications, then finally additions. In this case this gives 80.
Step 4: repeat the above three steps for the other values of the input set, giving {80, 310, 1220}.
b Define whether each of the following functions is linear, polynomial, exponential or logarithmic.
i f(x) = 5x5 + 7x2 + 9
Polynomial, as x5 and x2 both appear in the calculation.
ii f(x) = log10(x) – 9
Logarithmic, as the logarithm of x with base 10 is calculated.
iii f(x) = 5(x + 1)
Exponential, as the input value is used as the power to raise to (in this case, x + 1).
iv f(x) = 7x + 1
Linear, as it does not contain a polynomial, logarithm or exponent.

92 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


B Guided questions

10  Big-O notation and complexity of algorithms


Copy out the workings and complete the answers on a separate piece of paper.
1 For the following functions, give the set of output values if the input set = {2, 4, 6, 8}.
a f(x) = 2(x – 1) + 7
b f(x) = x3 – x2 + 8
c f(x) = 18x – 18
Step 1: take the first value from the input set.
Step 2: replace x in the equation in the question with this value and calculate the output.
Step 3: repeat the above steps for the other values of the input set.
2 Eight students organise themselves into a particular order. Calculate how many
permutations of the order of these eight students are possible.
Step 1: decide how many values are in the input set (in this case, how many students
are there?).
Step 2: find the factorial of this number. For example, the factorial of 4 is 4 × 3 × 2 × 1.
3 A computer program written in Python includes the following function:
def new(x) :
y = (x*x)
y = y + 7
return y
Calculate the output from the function if new(5) is called in the program.
Step 1: decide the value that will be assigned to x when the function is called.
Step 2: follow through each line of the function, keeping track of the contents of
variables x and y at each step.
Step 3: when the return keyword is encountered, identify the value that will be
outputted.

C Practice questions
4 A player of a card game chooses four cards and can play these cards in any order she
chooses. Calculate the number of permutations available.
5 For the following functions, give the set of output values if the input set = {2, 4, 6, 8}.
a f(x) = 2x – 1
b f(x) = 5x + x
c f(x) = x4 + x2
6 Define whether each of the following functions is linear, polynomial, exponential or
logarithmic.
a f(x) = 12 + log2(x)
b f(x) = 7x3 + 2x2
c f(x) = 2x + 18

10 Big-O notation and complexity of algorithms 93


7 A computer program written in Python includes the following function:
10 Big-O notation and complexity of algorithms

def test(a) :
b = a * 3
if b > 10:
return (b – 10)
else:
return b
a Calculate the output from the function if test(2) is called in the program.
b Calculate the output from the function if test(7+3) is called in the program.
c Calculate the output from the function if test(7)+3 is called in the program.

Complexity of algorithms
Note: this topic is assessed at A-level only.
Every step in an algorithm takes a tiny amount of time for the processor to complete.
However, in complex algorithms, this time can add up to quite a significant amount. A
brute force algorithm to try every permutation of a 15-character password would take
over 500 years with a standard desktop computer.
It is useful to be able to compare algorithms to decide quite how complex they are.
Computer scientists use Big-O notation (pronounced ‘big oh’) to do just that. This
is called Big-O as it is written as O(x), where x is the worst case complexity of the
algorithm being analysed.
Big-O does not give us an answer for how quickly the algorithm will execute. Instead,
it gives an idea of how the execution time will increase as the size of the input data set
increases. An algorithm may run efficiently with a set of 10 input values, but how does
it scale up (that is, how quickly does it execute) with 10 000 or 1 million input values?
Big-O notation helps to answer this question.

Types of complexity
Algorithms with constant complexity are said to have complexity of O(1). This means
that, no matter how large or small the input set is, the algorithm always takes the same
amount of time to execute. These algorithms obviously scale perfectly!
Time to complete

Size of data

Figure 10.2 Constant complexity: time to complete

94 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


Algorithms that have logarithmic complexity O(log n)

10  Big-O notation and complexity of algorithms


increase their execution time at a slower rate than
the rate at which the data set increases (n here, and

Time to complete
in the following examples, stands for the size of the
data set). A good example of this is a binary search,
which increases the number of steps to be executed
by 1 every time the data set doubles. A binary search
of 4 numbers may take t steps, but a binary search
of 2000 numbers can be completed in 10t steps and
Size of data
a search of 2 000 000 numbers can be completed in
20t steps. Algorithms with O(log n) efficiency scale Figure 10.3 Logarithmic
extremely well. complexity: time to complete

Algorithms with linear complexity O(n) increase at


exactly the same rate as the size of the input data set
increases. For example, a program which uses a loop

Time to complete
to add up all of the numbers in the input set will have
complexity O(n). A set of 5 numbers may take 5 steps,
but a set of 100 numbers will take 100 steps to execute.

Size of data

Figure 10.4 Linear complexity:


time to complete
Algorithms with polynomial complexity O(nx), where
x is a number larger than 0, increase their execution
time at a greater rate than an algorithm with linear
Time to complete

complexity. If a function with quadratic complexity


O(n2) takes 1 step with 1 input value, increasing to
10 input values it will take 102 steps, or 100 steps.
Increasing to 100 input values will take 100 000 steps.
A function with cubic complexity O(n3) would increase
its execution time even more quickly as the size of the
input grows. Size of data

Figure 10.5 Polynomial


complexity: time to complete
Algorithms with exponential complexity O(xn), where
x is a number larger than 0, increase at an even greater
rate than polynomial complexity. If a function with
Time to complete

quadratic complexity O(n2) takes 2 steps with 1 input


value, increasing to 10 input values it will take 210
steps, or 1024 steps. Increasing to 100 input values
will take 2100 steps. This number has 31 digits and the
algorithm would take a standard computer trillions of
years to complete. Obviously, this is not practical, but
Big-O notation will tell us this before we spend time Size of data

writing the program and wondering why it is taking so Figure 10.6 Exponential
long to run. complexity: time to complete

10 Big-O notation and complexity of algorithms 95


Classifying an algorithm into the correct level of complexity involves going line by line
10 Big-O notation and complexity of algorithms

through the algorithm and looking at the complexity of each line or section. The beauty of
Big-O is that only the parts which have the most effect on how it scales up are included. The
types of complexity listed on the previous pages are arranged in order, with those with the
least effect at the top and those with the most effect towards the bottom.
For example, an algorithm may have three lines, one with complexity O(n), another with
complexity O(n2), and a third with complexity O(2n3). We can ignore the line with linear
O(n) complexity as this has less effect than the next two lines that both have polynomial
complexity. Of the next two lines, cubic complexity has more effect than quadratic
complexity. We can also ignore the multiplier of 2 in 2n3 as this has less effect than the
power. We can therefore say that this algorithm has O(n3) complexity.

A Worked examples
a An algorithm has an input data set of size n and takes 3n5 + 2n3 + 2n + 7 steps to run. Use Big-O
notation to state the complexity of the algorithm.
Step 1: look at each term and classify according to the type of complexity. 3n5 and 2n3 both have
polynomial complexity, 2n has exponential complexity and 7 has linear complexity.
Step 2: decide which of these has the highest complexity according to the notes. Here, this is the
exponential complexity.
Step 3: this algorithm therefore has O(2n) complexity.
b Use Big-O notation to give the complexity of the following algorithm where n is the size of the
input data set.
for x = 1 to n
for y = 1 to n
z = data[y]
print z
next
next
print ‘finished!’
Step 1: split the algorithm into sections: there is a nested loop with two instructions for each
repetition and then a print statement at the end.
Step 2: the two lines inside the nested loop run once when n = 1. The loop runs 4 times when n =
2 and 16 times when n = 3. This therefore grows with n2 complexity. As there are two instructions
inside the loop, this section takes 2n2 steps to execute.
Step 3: the final print statement is outside of the loop and so runs once no matter what the size of the
input. This statement has O(1) complexity.
Step 4: looking at the section with the highest complexity and simplifying, the whole algorithm has
complexity O(n2).

96 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


B Guided questions

10  Big-O notation and complexity of algorithms


Copy out the workings and complete the answers on a separate piece of paper.
1 An algorithm has an input data set of size n and takes n4 + 2n2 – 1 steps to run.
Use Big-O notation to state the complexity of the algorithm.
Step 1: look at the complexity of each term in the algorithm.
Step 2: decide which term has the most effect on the complexity of the entire
algorithm.
Step 3: write this in the form O(…).
2 An algorithm has an input data set of size n and takes 7n + 3 steps to run.
Use Big-O notation to state the complexity of the algorithm.
Step 1: look at the complexity of each term in the algorithm.
Step 2: decide which term has the most effect on the complexity of the entire
algorithm.
Step 3: if needed, remove any constants.
Step 4: write this in the form O(…).
3 Use Big-O notation to give the complexity of the following algorithm where n is
the size of the input data set.
for x = 1 to n
if data[x] mod 2 = 0
print ‘odd’
else
print ‘even’
end if
next
Step 1: trace through the algorithm, looking at the complexity of each section.
Step 2: as a loop is involved, look at how the number of steps increases as the data
size increases.
Step 3: when an equation for the number of steps taken for a data set of size n has
been found, pick out the term with the most effect on complexity.
Step 4: if needed, remove any constants.
Step 5: write this in the form O(…).

C Practice questions
4 An algorithm has an input data set of size n and takes 4n3 + 4n2 steps to run.
Use Big-O notation to state the complexity of the algorithm.
5 An algorithm has an input data set of size n and takes (log n) + 3 steps to run.
Use Big-O notation to state the complexity of the algorithm.

10 Big-O notation and complexity of algorithms 97


6 An algorithm takes 5 steps to run with a data set of 10 items and 5 steps to run with
10 Big-O notation and complexity of algorithms

a data set of 100 items. Use Big-O notation to state the complexity of the algorithm.
7 An algorithm takes 6 steps to run with a data set of 1 item and 36 steps to run with
a data set of 6 items. Use Big-O notation to state the complexity of the algorithm.
8 Use Big-O notation to give the complexity of the following algorithm where n is the
size of the input data set.
if n > 10 :
for x = 1 to n
y = data[n]*7
print y
next
else
y = 7
print y
end if

98 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


Exam-style questions

1 a Convert the denary number 183 into an 8-bit binary number. (1)
b Convert the binary number 01101011 into denary. (1)
c Convert the denary number 153 into hexadecimal. (1)
d Convert the hexadecimal number F0 into denary. (1)
e State how many different numbers can be represented with 16 bits. (1)
2 a State how many kB are in 3 MB. (1)
b State how many bytes are in 1 GB. (1)
c Describe the difference between a MiB and a MB. (3)
3 State the result of each of these calculations.
a 10 DIV 2 (1)
b 100 MOD 3 (1)
c 2 MOD 5 (1)
d 50 DIV 50 (1)
4 IF x <= y THEN
OUTPUT x
ELSE
OUTPUT y
END IF
a State the output of this algorithm if x = 2 and y = 3. (1)
b State the output of this algorithm if x = 5 and y = 5. (1)
c State the output of this algorithm if x = 100 and y = 99. (1)
5 01 x = 0
02 DO
03 INPUT x
04 UNTIL x != 0
State the purpose of line 04. (1)
6 a Perform the binary addition 01100110 + 10000110. (2)
b i Perform the binary addition 10111010 + 11011001. (2)
ii Explain the error that would occur with your answer to part bi. (2)
7 a Perform the binary multiplication 0101 × 11. (3)
b Perform the binary multiplication 111011 × 110. (3)
c i Convert the denary numbers 30 and 3 into binary. (2)
ii Perform the binary multiplication between the two binary numbers from part ci. (3)

Exam-style questions 99
8 a Convert the denary number –50 into an 8-bit sign and magnitude number. (1)
Exam-style questions

b Convert the denary number 100 into an 8-bit sign and magnitude number. (1)
c Convert the denary number 329 into a sign and magnitude number. (1)
d Convert the denary number –444 into a sign and magnitude number. (1)
9 a Convert the sign and magnitude number 01101101 into denary. (1)
b Convert the sign and magnitude number 10101110 into denary. (1)
c Convert the sign and magnitude number 010110110110 into denary. (1)
d Convert the sign and magnitude number 111011011010 into denary. (1)
10 a Convert the denary number –42 into an 8-bit two’s complement number. (1)
b Convert the denary number 75 into an 8-bit two’s complement number. (1)
c Convert the denary number 299 into a two’s complement number. (1)
d Convert the denary number –501 into a two’s complement number. (1)
11 a Convert the two’s complement number 01011000 into denary. (1)
b Convert the two’s complement number 11111100 into denary. (1)
c Convert the two’s complement number 010001111001 into denary. (1)
d Convert the two’s complement number 100011101011 into denary. (1)
12 a Perform the binary subtraction 25 – 5. (3)
b Perform the binary subtraction 100 – 50. (3)
c Perform the binary subtraction 294 – 63. (3)
d Perform the binary subtraction 1000 – 992. (3)
13 a Convert the unsigned fixed point number 01011.101 to denary. (2)
b Convert the unsigned fixed point number 11011011.0101 to denary. (2)
c Convert the two’s complement fixed point number 101011.0101 to denary. (3)
d Convert the two’s complement fixed point number 0101.10101 to denary. (2)
14 a Convert the denary number 23.375 into unsigned fixed point. (2)
b Convert the denary number 100.75 into unsigned fixed point. (2)
c Convert the denary number 20.34375 into two’s complement fixed point. (2)
d Convert the denary number –30.34375 into two’s complement fixed point. (2)
15 a i Perform a 2-place right shift on the 8-bit binary number 10010110. (1)
ii Explain the impact of the shift performed in part ai on the binary number. (2)
b i Perform a 3-place left shift on the 8-bit binary number 10110111. (1)
ii Explain the impact of the shift performed in part bi on the binary number. (2)
16 a Perform a bitwise OR operation on 10101101 using the mask 11111111. (1)
b Perform a bitwise AND operation on 10101111 using the mask 10101010. (1)
c Perform a bitwise XOR operation on 00110110 using the mask 11011111. (1)
d Perform a bitwise NOT operation on 10111011. (1)
17 Two vectors A and B are stored as A = (12, 15) and B = (25, 55).
a Calculate the result of adding the vectors A and B together. (2)
b Calculate the result of a dot product of these two vectors. (1)
c i Multiply vector A by the scalar 5. (1)
ii Multiply vector B by the scalar 15. (1)

100 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


18 For each of the following, state which number set(s) they belong to:

Exam-style questions
a 180 – 15 × (6 + 7) (1)
b 15.73 (1)
c 9 (1)
d 10 (1)
19 If A = {10, 20, 30, 40, 50, 60, 70} and B = {5, 10, 15, 20, 25, 30} find:
a A∩B (1)
b {4x + 1 | x ∈ A } (1)
20 Find A where A = {x | x ∈  ∧ x >10 ∧ x < 20}. (1)
21 Calculate the denary values of the following floating point binary numbers. All
values are given in two’s complement and use 4 bits for the exponent and 4 bits for
the mantissa.
a 01001110 (1)
b 01100011 (1)
c 10100100 (1)
22 State whether each of the floating point binary numbers below is normalised or not.
a 010010101 (1)
b 000101101 (1)
c 101001010 (1)
d 110010100 (1)
23 Calculate the largest number that can be stored using a 10-bit binary number if
the number uses 6 bits for the exponent and 4 bits for the mantissa. (4)
24 Calculate the absolute and relative errors when:
a 256.72 is stored as 256 (2)
b 0.7 is stored as 1 (2)
c 947 is stored as 900 (2)
25 A bitmap image with resolution 256 × 1024 uses 136 unique colours. Calculate
the file size of the image in kilobytes. (4)
26 A 1-minute sound file is recorded using a sample resolution of 16 bits and a
sample rate of 44 kHz. Calculate the file size in megabytes, giving your answer
to 3 decimal places. (2)
27 Complete the truth table for the expression A AND B OR (NOT C). (8)

Table E.1

A B C A AND B OR (NOT 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

Exam-style questions 101


28 Write each of the following as a Boolean expression.
Exam-style questions

a A = NOT(B AND C) OR D (1)


b A = (B XOR A) AND (NOT C) (1)
c A = B OR NOT C AND (D OR C) (1)
29 Show that ¬ (A ∨ ¬ B) ∧ ¬ B is equivalent to 1. (5)
30 For the following functions, give the set of output values if the input set = {7, 14, 21}.
a f(x) = 4x2 + 3x – 7 (1)
b f(x) = 9x + 4 (1)
31 An algorithm has data size n and takes n3 – n2 + 7n – 4 steps to run. Use Big-O
notation to define the complexity of the algorithm. (1)

102 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers


Appendix

Specification cross–reference
The information in the table below is intended as a guide only. You should refer to your
specification for full details of the topics you need to know.

AS A-level A-level AS A-level AS A-level


Unit Section OCR OCR AS AQA AQA WJEC WJEC EDUQAS EDUQAS
1 Number 1.4.1 1.4.1 3.5.2.1 4.5.2.1 4 U4 3 2.1.4 2.2.3
systems
Sets 4.4.2.2
2 Converting base 1.4.1 1.4.1 3.5.2.1 4.5.2.1 4 U4 3 2.1.4 2.2.3
2/base 16 to base
10
Converting base 1.4.1 1.4.1 3.5.2.1 4.5.2.1 4 U4 3 2.1.4 2.2.3
10 to base 2/
base 16
3 Binary prefixes 3.5.3.2 4.5.3.1
Decimal 3.5.3.2 4.5.3.1
prefixes
4 Arithmetic Comp 2 Comp 2 3.1.1.3 4.1.1.3 9 2.1.9 2.1.3
operations: DIV,
Mod, Power,
Rounding and
truncating

Logical Comp 2 Comp 2 3.1.1.4 4.1.1.4 3 U3 3 2.1.2 2.1.2


operations
5 Signed vs 1.4.1 1.4.1 3.5.4.1 4.5.4.1 U4 3 2.1.4 2.2.3
unsigned binary
Key values for 1.4.1 1.4.1 3.5.3.1 4.5.3.1 U4 3 2.1.4 2.2.3
n bits
Binary addition 1.4.1 1.4.1 3.5.4.2 4.5.4.2 4 U4 3 2.1.4 2.2.3

Binary 1.4.1 1.4.1 3.5.4.2 4.5.4.2


multiplication
Representing 1.4.1 1.4.1 4 U4 3 2.1.4 2.2.3
negative
numbers: Sign
and magnitude
Representing 1.4.1 1.4.1 3.5.4.3 4.5.4.3 4 U4 3 2.1.4 2.2.3
negative
numbers: Two’s
complement

Appendix 103
Representing 1.4.1 1.4.1 3.5.4.3 4.5.4.3
Appendix

negative
numbers:
Subtracting
with two’s
complement

Fixed point 1.4.1 1.4.1 3.5.4.3 4.5.4.4


Logical shifts 1.4.1 4.7.3.5 U3 2 2.2.3
Bitwise 1.4.1 4.7.3.5 U4 3 2.1.2
operators
6 Floating point 1.4.1 1.4.1 4.5.4.5 4 U4 3 2.1.4 2.2.3
binary
Normalisation 1.4.1 1.4.1 4.5.4.8 U4 3 2.1.4 2.2.3
Range and 1.4.1 1.4.1 4.5.4.7 U4 3 2.1.4 2.2.3
precision
Errors 1.4.1 1.4.1 4.5.4.7 U4 3 2.1.4 2.2.3
7 Bitmap images 3.5.6.4 4.5.6.4
Sound samples 3.5.6.1 4.5.6.1
8 Logic gates 1.4.3 1.4.3 3.6.4.1 4.6.4.1 2 U3 2 2.1.1 2.1.2
Boolean algebra 1.4.3 1.4.3 3.6.5.1 4.6.5.1 2 U3 2 2.1.1 2.1.2
Boolean 1.4.3 1.4.3 3.6.5.1 4.6.5.1 2 U3 2 2.1.1 2.1.2
identities and
De Morgan’s
laws
9 Vector 4.2.8.1
representation
Vector addition 4.2.8.1
Scalar vector 4.2.8.1
multiplication

Dot product 4.2.8.1


of two vectors
Convex 4.2.8.1
combination of
two vectors
10 Functions 2.3.1 1.4.3 4.12.1.2 4.4.4.2 9 U3 3 2.1.9 2.1.3

Complexity of 1.4.3 4.4.4.2 U3 3 2.1.3


algorithms

104 Full worked solutions at www.hoddereducation.co.uk/essentialmathsanswers

You might also like