Extracted Pages From Cambridge IGCSE Computer Science

Download as pdf or txt
Download as pdf or txt
You are on page 1of 51

ENDORSED BY

~;~.~ CAMBRIDGE
\t.~ lnt~mational F.11aminarmns

Cambridge
IGCSE®
Computer
Science
-
,.,,.,.__ ,ff David Watson
Helen Williams

/.
1 HODDER
EDUCATION
Cambridge

IGCSE®
Computer
Science
This page intentionally left blank
Computer
Science
David Watson
Helen Williams

i.7 HODDER
EDUCATION
AN HACHETTE UK COMPANY
Acknowledgements
p. l tTCi.Stockphoto.com/Dcnn}~Bisogno 0 etc
t - top 0 h - bottom.l - left 0 , - right 0 , - ccntn:
Computer hardw= ond 101iware brand nama mentioned in thi, ""°"•«protected by their rnp«ln'< tndenurlu 2nd
:arcadmowkdged.
S..T.1.tchi>dcvdopcdbytheLifclongKinde<g•rtcnGroupattheMITMediaLab.Scchttp://,crnch.mit.edu
Every effort h:n'C been m•dc totrxc all copyright hold=. but if•ny have been in•dvatentlym"Crloohd the pubHsh=
,.;Ubc:plcascdtomakethcncce..uyarrangemcnnatthcfimopportunity.
Although every effort h .. been made to cnsun: that wd><ite addresses arc correct at time of going to press. Hodder
Educationcannotbchddrc,pomiblefo,thccontentof2ny"''<b,itcmentionedinthi,book.ltis>0metimc,possiblcto
find • n:located ,...,1,
page by typing in the ,dd,a, of the home page foe • website in the URL window of you, broW>Cr.

Photo credits
p. l Cl pcno- Fotolia; p. 15 Cl Dmitrydcsigner/Fotolia; p. 16 Ci.Stockphoto.com/K,d Yamashita; p.57 C Romanchud-
Fotoli,: p.58 tC C Squa«od Studios/Pbotodisc/Getty lrrugcs. "'ClDmitriy Mclnikov - Fotolia.com. bCl Popovi Olga/
Fotoli•; p.59 C piufu.'C - FotoH• ; p.65 C Manfred Schmidt -Fotolia.com; p.67 Cl dja65 - Fotolia; p.68 C Komuntin
Shcvt,ov - Fotolia; p.69 t Cl Miguel Nnarro/Stone/Gctty Image,. b C l'iero Cruciatti/At.my; p.73 Cl J,undesign/
Fotoli•; p.78 ond 79 C adiu - Fotolia; p.8 1 C Mykola M>zuryk- Fotolia; p.82 tCl Mauro Rodrigues/Fotolia,
b CManin Dolun/Scknce Photo Libr-.ry; p.83 C Nornun Chan - Fotolia; p.85 C Studio 10 /Alamy; p.86 C Brcnn:rn
~tg,t.";;:t:_~:::.~~~~~~~Jt',t')~~~~~ ~!:t..:.!~t;/~;{_;!<~;;'1'.a:::;_rF~!....

H>ehctte UK', poHcy is to me p>p<r> that an: natucal, renewable 2nd =ydable products and made &om wood grown in
susuinablefuccm.Thcloggingandmanuh.turingproccssc,:arc expc<tedtoconformtotheenvimnmenulrs,gulatiom
ofthecountryoforigin.
On:len: plea,c contact ~ i n t Ltd, 130 Milton P:uk, Abingdon, Oxon OXl4 4SB. Telephone: (44) 01235 827720.
~ : t < : . i i : i J ! =.i,~.;:,.:;'~:;'.~:;;s.OO.MondaytoSatun:by. "itha H-hou,rncs,agc •mwcring,crvice.

II!) !GCSE i, the registered tcadcfilm of Cambridge International Examination,


C llivid Watson and Helen WiUiarm 2014

~:s;i,b~!:!~:;014 by

tn11:'~1U3~~rnpany

lmpr=ionnumbc,54321
Yeac201520142013
AU right, rac"'Cd. Apart from rny use pcrntitted under UK copyright law. no part of this publication may be reproduced
or tcammitted in any form or by2ny mcan,, electronic or ma:lunic.t. including photocopring 2nd r,ccording. or held
"ithin any information nonge and rctriev.d •J~t=. without pcnni,sion in wriring &om the publish«"' undcc licence
fromtheCopyrightl.icensingAgencyLimited. Funhcrdctail,of.ruch~ccncc.(fucrcproy.,phicrcproduction)maybe
obuinedfromthcCopyrightLicemingAgencyl.imited 0 s,,ffi-onHou>e 0 6--IOKirbyStrcct 0 LondonECIN8TS
CoverphotoCScannil-FotoHa
Thirdeditiontypactinll/13ptGalliardRomanbyAptaralnc.

Acrcaloguc:«cordfo,thi, titlcis:n.. ilablefromthcBritishl.ibr:uy


I SBN 978 1471809309
Contents
Introduction viii

Section 1 Theory of computer science


Chapter 1 Binary systems and hexadecimal
1.1 Introduction
1.2 111c binary system
1. 3 M easurement of the size of computer memories
1.4 Example use ofbinary
1. 5 The hexadecimal system
1.6 Use of the hexadecimal system

Chapter 2 Communication and internet technologies 14


2.1 Introduction 14
2.2 Data transmission 14
2.3 Error-checking methods 17
2.4 lntcrnet technologies 22

Chapter 3 Logi c gates and logic circuits 26


3 .1 Introduction 26
3 .2 Logic gates 26
3 .3 Truth tables 26
3.4 The fimction ofthe six logic gates 27
3.5 Logic circuits 29
3 .6 Logic circuits in the real world 38

Chapter 4 Operating systems and computer architecture 42


4.1 Introduction 42
4.2 Operating systems 42
4.3 Interrupts 43
4.4 Computer architecture 45
4 .5 The fetch-execute cycle 49

Chapter 5 Input and output devices 51


5 .1 Introduction 51
5 .2 ln putdeviccs 51
5 .3 Outputdevices 67

Chapter 6 Memory and data storage 76


6.1 Introduction 76
6.2 File formats 76
6.3 Lossless and lossy file compression 80
6.4 Memory and storage 81
6.5 H ow to estimate the size ofa file 88
Chapter 7 High- and low-level languages 90
7.1 Programming languages 90
7.2 Translators 92
7.3 What happens when things go wrong? 94

Chapter 8 Security and ethics 97


8.1 Introduction 97
8.2 Security and data integrity 97
8.3 Cookies 100
8.4 Loss of data and data corruption 101
8.5 Firewallsandproxyservers 102
8.6 Security protocols 103
8.7 Encryption 104
8.8 Applications 109
8.9 Computer ethics 110
8.10 Freesoftware,freewareandshareware 111

Section 2 Practical problem-solving and programming 114


Chapter 9 Problem-solving and design 115
9.1 Introduction 115
9.2 Algorithms 118
9.3 Test data 119
9.4 Validation and \·erification 120
9.5 Using trace tables 125
9.6 Identifying and correcting errors 127
9.7 Producing algorithms 129

Chapter 10 Pseudocode and flowcharts 134


10. l Introduction 134
10.2 Assignment 134
10.3 Conditional statements 135
10.4 Loop structures 137
10.5 Input andoutputstatements 139
l 0.6 Standard actions 139
10.7 Exan1ples of algorithms in pseudocode 139
10.8 Standard flowchart symbols 142

Chapter 11 Programming concepts 146


11. l Introduction 146
11.2 Programming 146
11.3 Declaration and use of variables and constants 149
11.4 Basic data types 150
11.5 How to make your program work 151
Chapter 12 Data structures: arrays and using pre-release material 163
12.1 Introduction 163
12.2 Arrays 163
12.3 Using pre-release material 168

Chapter 13 Databases 169


13.1 Introduction 169
13.2 What are databases used for? 169
13.3 TI1e strucrnre ofa database 169
13.4 Practical use of a database 171

Index 178
I ntrod ucti on

A ims
l11is textbook has been written to provide the knowledge, understanding and
practical skills that a student would need for the Cambridge Internntional
F.xaminations Computer Science I GCSE and GCE O Level courses.
The textbook is part of a package which includes a student CD-ROM. A
teacher's CD-ROM is also available separately which includes additional guidance
and other useful information ( see later in this introduction ).
This OC>Ok and accompanying student CD-ROM provide:
• practice end-of-chapter questions which include questions from past Cambridge
International Examinations papers
• activities which gi\·e students additional guidance and practice
• sample program solutions for programming activities
• hints and tips where these provide additional help and knowledge.
Although this book has been written with the Cambridge lnter11atio11al
F.xaminatiom syllabus in mind, it can still be used as a useful reference textbook
for other GCSE computing courses. It is also a useful source of information for
those srudcnts starting an A le\·el computer science course ~ especially at AS level.

Using the book


111c textbook contains 13 chapters. Although it is possible for some elements
of the practical problem-solving chapters to be examined in Paper I (Theory
of Computer Science ), and vice versa, the sections for the theory work are
in Chapters 1 to 8 and the practical work in Chapters 9 to 13. The book has
been split into Section 1 (TI1eory of computer science ) and Section 2 ( Practical
problem-solving and programming) to follow the Cambridge International
F.xaminatiom syllabus as closely as possible.
Activities are shown throughout the books as follows:

( Activity 1.1
)
Student CD-ROM
TI1e accompanying student CD-ROM contains additional guidance to enhance
the learning process in a number ofkeyareas in the textbook. The CD-ROM uses
animation and verbal commentary wherever this is found helpful in the learning
process. The CD-ROM includes sample program solutions for the programming
activities.
Where book topics are included in the CD-ROM the following symbol is used: 0
Teacher's CD-ROM
An additional teacher's CD-ROM is available to accompany this textbook. TI1is
CD-ROM includes the following material:
• possible responses to sample examination and other guestions
• each guesrion part suggests a level of difficulty
• expected responses to the guesrions at that level are included
• additional notes on why the responses meet the required level only
• answers to the end-of-chapter 'luestions in this textbook and to some of the
activities where relevant
• program files in Python and Java for activities and end-of-chapter questions.
• a scheme of work to help teacher's plan their r.110 -year computer science course;
this scheme includes:
• chapter numbers from the book
• topic to be covered from the chapter
• approximate time alkx:ation adllised to cover the topic
• Cambridge lnten1ational F.xaminationssyllabus reference
• relevant page numbers from the textbook
• activities found in the textbook to help in the teaching process
• any additional notes to help plan the lessons.
The teacher's CD-ROM has not been through the Cambridge endorsement
process.
David W<Jtson and Helen Williams
September 2014
This page intentionally left blank
G) Binary systems and hexadecimal
lnthischapteryouwilllearnabout:
e thebinarysystem
• measurement of computer memories
e thehexadecimal1ystem
e howtoconvertnumbersbetweendifferentnumberbasesystems

1.1 Introduction
As you progress through this book you will begin to realise how complex
computer systems really are. By the time you reach Chapter 12 you should ha\·e a
better understanding of the fundamentals behind computers themselves and the
software that controls them.
Howe\'er, no matter how complex the system, the basic building block in all
computers is the binary number system. This system is chosen since it consists of
ls and Os only. Since computers contain millions and millions of tiny 'switches',
which must be in the ON or OFF position, this lends itsclflogically to the binary
system. A s,.vitch in the ON position can be represented by l; a switch in the OFF
position can be represented by 0.

1.2 The binary system


We arc all familiar with the dcnary (base 10 ) number system which counts in
multiples of 10. This gives us the well -known headings of units, 10s, 100s, 1000s
and soon:
10 OOO 1000 100 10

( 104) ( 101 ) ( 102 ) ( 101 ) ( 100)


111c BINARY SYSI"EM is based on the number 2. Thus, only the two 'values' 0 and
I can be used in this system to represent each digit. Using the same method as
dcnary, thisgi\·cs the headings of 20, 21, 22, 23 and so on. The typical headings
for a bi.nary number with eight digits would be:
128 64 32 16

A typical binary number would be:


111011 I 0

1.2.1 Converting from binary to denary @


It is fairly straightfonvard to change a binary number into a dcnary number.
Each time a 1 appears in a column, the column value is added to the total. For
example, the binary number above is:
128 + 64 + 32 + 8 + 4 + 2 - 238 (dcnary )
The O values arc simply ignored.

0
1.2 Th e binary system

Activity 1.1
Convertthelollowingb.narynumber,;
intodeoary:
a 00110011
b 01111111
c 10011001
d 01110100
e 11111111
f 00001111
g 10001111
h 11110000
i 01110000
j 11101110

1.2.2 Converting from denary to binary ®


The reverse operation , converting from denary to binary, is slightly more
complex. There are two basic ways of doing th is. The first method is 'trial and
error' and the second method is more methodical and involves repetitive division.
Method l
Consider the conversion of the dcnary number, 107, into binary. This method
involves placing l s in the appropriate position so that the total equates to 107:
128 64 32 16

M eth od 2
This method involves successive division by 2. The remainders arc then read from
BOTTOM to TOP to give the binary value. Again using 107, we get:

readlhe,emainde,lrombottomto
toptogetlhebiM,ynumbef
0 1 1 0 1 0 1 1

Figure 1.1

Activity 1.2
Convertthelollowingdenarynumbersinto
biMry{usingbothmethods)
• 41
b 67
' 86
d 100
e 111
f 127
g 144
h 189
i 200


j 255
1 BINARY SYSTEMS AND HEXADECIMAL

1.3 Measurement of the size of computer memories


A binary digit is commonly referred to as a BIT; 8 bits are usually referred to as a

The byte is the smallest unit of memory in a computer. Some computers


use larger bytes but they are always multiples of8 (e .g. 16-bit systems and
32 -bit systems). One byte of memory wouldn't allow you to store very much
information; therefore memory size is measured in the following multiples:

1kiim,te(1KB)
(1MB)
e(1GB)
1terabvte(1Tl!)
1nPtabvte(1P!!)

(Note: 1024 x 1024 - I 048576 and so on.)


To give some idea of the scale of these numbers, a typical data transfer rate
using the internet is 32 megabits (i.e. 4 MB ) per second (so a 40 i\1.B file would
take 10 seconds to transfer ). Most hard disk systems in computers are 1 or
2 TB in size (so a 2 TB memory could store over half a million 4 MB photos, for
example).
It should be pointed out here that there is some confusion in the naming
of memory sizes. The IEC convention is now adopted by some organisations.
Manufacturers of storage devices often use the de nary system to measure storage
size. For example,
l kilobyte - 1000 byte

l megabyte - 1000000 bytes

I gigabyte - l 000000000 bytes

I terabyte - 1 OOO 000000 OOO bytes and so on.


111c ! EC convention for computer internal memories (including RAJ\1) becomes:
1 kibibytc ( l KiB ) - I 024 bytes

l mebibyte ( 1 MiB ) - I 048576 bytes

I gibibyte ( 1 GiB ) - l 073 741824 bytes

1 tebibyte ( 1 TiB ) - 1099511627776 bytes and so on.


H owe\·er, the IEC terms are not universally used and this textbook will use
the more conventional terms shown in Table 1. 1. This also ties up with the
Cambridge International E'l:aminations computer science syllabus which uses the
same terminology as in Table 1. 1.

1.4 Example use of binary


This section gives an example of a use of the binary system. \Ve will introduce the
idea of computer REGI STERS; this subject is covered in more depth in Chapter 4.
A register is a group ofbits; it is often depicted as follows:

0
1.5 The hexadecimal system

Figur• 1.2

\\'hen computers (or microprocessors ) are used to control devices (such as


robots ), registers arc used as par t of the control system. The following example
describes how registers can be used in controlling a simple device.
A robot vacuum cleaner has three wheels, A, Band C. A rotates on a spindle
to allow for direction changes (as well as forward and bachvard movement );
B and C are fixed to revolve around their ules to provide only forward and
backward mo\·ement, and have an electric motor attached :

Figur• 1.3

An 8-bit register is used to control the movement ofthe robot vacuum cleaner:

BdirPCtion C di rectioo
fllfWards frnwards

Figur•1.4

If the register contains I O 1 0 1 0 l O this means 'motor Bis ON and motorCis


ON t111d both motors are tuniing to produce FORiVARDS motion '. Effecti\·ely, the
vacuum cleaner is moving forwards.

Activity 1.3
a What would be the effect jf the register contained the follov,iing ~alues7
1 10011000

b What would the register contain if only motor C was ON and the motors were turning in a
BACKWARDS direction?
c What would the register contain if motor Band motor C were both ON but B was turning in a
backwarddirectionandCwa1turninginalorwarddirection?
d What would be the effect jf the register contained the follov,iing?
11111111

1.5 The hexadecima l system


The HEXADECIMAL SYSI"EM is very closely related to the binary system.
H exadecimal (sometimes referred to as simply 'hex') is a base 16 system and
therefore needs to use 16 different 'values' to represent each digit.


1 BINARY SYSTEMS AND HEXADECIMAL

Because it is a system based on 16 different digits, the numbers Oto 9 and


the letters A to F arc used to represent each hexadecimal (hex ) digit. (A - 10,
B - 11 ,C - 12 ,D - 13 , E - 14 and F - 15. ) Using the same method asdcnary
and binary, this gi\·cs the headings of 160, 161, 162, 163 and so on. The typical
headings for a hexadecimal number with five digits would be:
65 536 4 096 256 16 l
(lfrl) (163 ) ( 162) ( 161) ( 160)
Since 16 - 24 this means that FOUR binary digits arc cciuivalcnt to each hexadecimal
digit. Table 1.2 summarises the link between binary, hexadecimal and dcnary.

Bina ryvalu• De naryvalu •

1.5.1 Converting from binary to hexadecimal


and from hexadecimal to binary (v
Co1wcrting from binary to hexadecimal is a fairly easy process. Starting from
the right and moving left, split the binary number into groups of 4 bits. If the
last group has less than 4 bits, then simply fill in with Os from the left. Take each
group of4 bits and convert it into the cciuivalcnt hexadecimal digit using Table 1.2.
Look at the following two examples to sec how this works.

Examp le 1
I O 1I111000 0 1
First split this up into groups of 4 bits:
101 1 111 0 0 0 0 I
TI1cn, using Table 1.2, find the CCJliivalcnt hexadecimal digits:

Examp le 2
100 0 0 I 111 111 0 l

0
1.5 The hexadecimal system

First split this up into groups of4 bits:


I O OOO I 1111 1101
The left group only contains 2 bits, so add in two Os:
0 0 I O OOO I 1111 1101
Now use Table 1.2 to find the equivalent hexadecimal digits:
D

Activity 1.4
Convertthelollowingb4narynumbers
into hexadecimal·
a 11000011
b 11110111
c 1001111111
d 10011101110
e 000111100001
f 100010011110
g 0010011111110
h 0111010011100
i 1111111101111101
j 00110011110101110

Con\'erting from hexadecimal to binary is also very straightforward . Using the


data in Table 1.2 , simply take each hexadecimal digit and write down the 4-bit
code which corresponds to the digit.

Examp le 3
A
Using Table 1.2 , find the 4 -bit code for each digit:
0 100 0 10 I 101 0
Put the groups together to form the binary number:
0 100 0 101 l O 1 0
Examp le 4

Again just use Table 1.2:


1011 l 111 0 00 0 100 0
Then put all the digits together:

10111111 0000 1000

Activity 1.5
Convertthelollowinghexadedmalnumbersintobinary·
a 6C f BA6
b 59 g 9((
c AA h 40AA
d AOO i DA47
J 1AB0

0
1 BINARY SYSTEMS AND HEXADECIMAL

1.5.2 Converting from hexadecimal to denary


and from denary to hexadecimal ®
To con\'ert a hexadecimal number to denary is fairly straightforward. Take each
hexadecimal digit and multiply it by its value . Add the totals together to obtain
the dcnary\'aluc.

Examp le 1
A
First multiply each digit by its value:
256 16
(4 x 2 56 - 1024 ) ( 5 x 16 - 80) (10 x 1 - 10 ) (Note: A - 10)
Add the totals together:
denary number - 1 l 1 4

Examp le 2

First multiply each digit by its value:


256 16
(12 x 256 - 3072) (8 x 16 - 128 ) (15 x 1 - 15 ) (Note: C - 12 and F - 15 )
Add the totals toge ther:

dcnary number - 3 2 1 5

Activity 1.6
Coovert the following heXildedmal number,;
intodenary:
a 6B
b9 C
< 4A
d FF
e 1FF
f AOl
g BB4
h CAB
i 12AE
j A089

To con\'ert from denary to hexadecimal is a little more difficult. As with the


cotwersion from binary to dcnary, there arc two very similar methods that can be
used. Again, the first method is 'trial and error' and the second method is more
methodical and im·olvcs repetitive division.

0
1.6 Use of the hexadecimal system

Method l
Consider the conversion of the dcnary number, 2004, into hexadecimal. This
method involves placing hexadecimal digits in the appropriate position so that the
total eguatesto2004:
256 16
D (Note: D - 13 )
A quick check shows that: (7 x 256 ) + ( 13 x 16) + (4 x 1) gives 2004.
Method 2
This method involves successive division by 16. The remainders are then read
from BOTTOM to TOP to gi\·e the hexadecimal value. Again using 2004, we get:

" ~""'
16 125 ,em.;nder : 4 rei>dtherem.;nderfmmbottomtotop
16

Figur•1.5
7 ,emaamier: 13
0 ,em.;nder : 7 1'0'
togetthehexadecimalnOO'lber:

Activity 1.7
Convertthelollowingdenarynumbers
intoheXddecimal{uloingbothmethods):
a 98
b 227
c 490
d 511
e 826
f 1000
g 2634
h 3743
i 4007
j SOOO

1.6 Use of t he hexadecimal system


This section reviews five uses of the hexadecimal system. 111c information in this
chapter gives the reader sufficient grounding in each topic at this le\'el. Further
material can be found by searching the internet, but be careful that you don't go
off at a tangent.

1.6.1 Memory dumps


Since it is much easier to work with: B 5 A 4 I A F C
rather than: l O 1111001110 1 olo 10010001110101111111100
hexadecimal is often used when developing new software or when trying to
trace errors in programs. The contents of part of the computer memory can
hold the key to help solve many problems. When the memory contents are
output to a printer or monitor, this is known as a MEMORY DUMP:

0
1 BINARY SYSTEMS AND HEXADECIMAL

1-·· ....... ··················1


009901'77

00990E9 E

00990EA5
n

74
20 6D 65 6D 6F

H 20 73
12

69
79 20

6F 77
64

69
75 6D 70 20 66 72 6F 6D 20 20

797069636l6C2020636F6D707574657220206D85

6D 6F 72 611 67 20 74 68 65 20 20 63 6F
61

61!

00990EBC 746561?74 73206F66206l206ll756D62657220206F66

00990ED3 6C6F63 6l 74696F61173 2020696E2020696578202020

00990BIIA 6116F74 6l 74696F61120200000000000000000000000

Figu re 1.6

A program developer can look at each of the hexadecimal codes ( as shown in


Figure 1.6) and determine where the error lies. The value on the far left shows
the memory location so that it is possible to find out exactly where in memory tl1e
fault occurs. This is clearly much more manageable using hexadecimal rather than
using binary. It's a very powerfid fault-tracing tool, but requires c.onsiderable
knowledge of computer architecture in order to interpret tl1e results.

1.6.2 HyperText Mark-up Language (HTM L)


HYPERTEXT MARK·UP LANGUAGE (HTML ) is used when writing and
de\·eloping web pages. HTML isn't a progranuning language but is simply a
mark -up language. A mark -up language is used in the processing, definition and
presentation of text ( for example, specifying the colour of tl1e text ).
HTML uses <tags> which are used to bracket a piece of code; for exan1ple,
<td> starts a standard cell in an HTML table, and </td> ends it. Whatever is
berween tl1e two tags has been defined. H ere is a short section of HTML code:

<hJ :,Used car sales</hJ >


<h2>Cars f rom $500</h2>
<br><h2:>Cash sales only</h2></td></br>

HTML code is often used to represent colours of text on the computer screen.
1l1e values change to represent different colours. The different intensity of the
three primary colours (red, green and blue) is determined by its hexadecimal
value. For example:
• # FF 00 00 represents primary colour red
• # 00 FF 00 represents primary colour green
• # 00 00 FF represents primary colour blue
• # FF 00 FF represents fuch sia
• # FF 80 00 represents orange
• # B 1 89 04 represents ta n
1.6 Use of the hexadecimal system

and so on producing almost any colour the user wants. There are many websites
available that allow a user to find the HTML code for the colour needed.

Activity 1.8
Usingtheinternet,findtheHTMLtodesforanumberofcolours
Try entering HTML code into the computer and see how the colours and font types can be
changed to good effect
Make use of websites, ,;uch as www.html .arrl toproduce your own web pages
With a little practice, you can import/embed images into your own design of web page using
freely available software.
Remember this is not a programming language. It is s.imply a mark-up language, so vecy little
programmingskillisrequilrotouseHTML

1.6.3 Media Access Control (MAC)


A MEDIA ACCESS CoNTROL (MAC) ADDRFSS refers to a number which uniguely
identifies a device on the internet. The MAC address refers to the network
interface card (NIC ) which is part of the device. The ,\1AC address is rarely
changed so that a particular device can always be identified no matter where it is.
A MAC address is usually made up of 48 bits which are shown as six groups of
hexadecimal digits (although 64-bit addresses are also known ):
NN - NN - NN - DD - DD - DD

NN:NN:NN:DD:DD:DD
where the first half ( NN - NN - NN ) is the identity number of the manufacturer
of the device and the second half (DD- DO - DO ) is the serial number of the
device. For example: 00 - l C - B3 - 4F - 25 - FE is the MAC address of a device
produced by the Apple Corporation (code: 001 CB3 ) with a serial number of
4F25FE. Sometimes lower case hexadecimal letters are used in the MAC address:
OO - lc-b3-4f-25 -fe. Other manufacturer identity numbers include:

• 00 - 14 - 22 which identifies devices made by Dell


• 00 - 40 - 96 which identifies devices made by Cisco
• 00 - AO - C9 which identifies devices made by Intel, and so on.

Types of MAC address


It should be pointed out that there are mu types of MAC address: the
UN IVERSALLY ADM IN ISTERED MAC ADDRESS (UAA) and the LocALLY
ADM INI STERED MAC ADDRESS (LAA).
The UAA is by far the most common type of MAC address and this is the one
set by the manufacturer at the factory. It is rare for a user to want to change this
MAC address.
H owever, there are some occasions when a user or an organisation wishes to
change their MAC address. This is a relati\·ely easy task to carry out but it will
cause big problems if the changed address isn't unique.
There are a fei.11 reasons why the MAC address needs to be changed using LAA:
• Certain software used on mainframe systems needs all the MAC addresses of
devices to fall into a strict format; because of this, it may be necessary to change
the MAC address of some devices to ensure they follow the correct format.


1 BINARY SYSTEMS AND HEXADECIMAL

• It may be necessary to bypass a MAC address filter on a router or a firewall;


o nl y ,\1AC addresses with a certain format are allowed through, otherwise the
devices will be blocked.
• To get past certain types ofnen11ork restrictions it may be necessary to emulate
unrestricted MAC addresses; hence it may require the MAC address to be
changed on certain devices connected to the nen11ork.

1.6.4 Web addresses @


Each character used on a keyboard has what is known as an ASCII CODE
(AM ERICAN STANDARD CODE FOR INFORMATION INTERCHANGE). These codes can
be represented using hexadecimal values or decimal values. Figure 1.7 shows part
of an ASCII table.
,. .... .,,.. .. ,. ..
,
.
"'"
Char O« Chu

" "
.. " " "'
<:SPACh

"" '
,,"" "" "" "'" ""
A

SS
s "" .
" '0 ""'' "
..
;e
";s """ '
"'"
" "" ' ""
"n
"
." G'' '"
'"
'" . " .
'

.
""'"
" K
"'"
>A

'"
n

",s
"n
.
"
<A

.,"
'"
'
'
'M
'"
'"'
'"'
'"
""
.
SA"
.
'
"""'
"" ""
. '"' m

."
"
"
,,""'
'
0

'
'"
.,"""
""
S>
S>
"
0

Q
'"
"'
"'
m
""
"n
.
.,"'
.
s,
S>
' '' '"
a;
,,.
m n

..
'
S>
s,
" '' "" '" ",s '
SS SS
"" "" ' "'
SS
"'"" ' "'" "
"""
w
'
""
'" ,."n w

"'"'" "
aA ' "'"' SA
''
'"
"'m "
>A
I m I
""' ""'" "" SC '" ' "' K'"
.," so m I

" "" ' """ "" ""


m
""
" <:OHETb
Figure 1.7
A good example of the use of ASCII codes is the representation ofa web address
(or URL, which stands for uniform resource locator) such as www.hoddcr.co.uk
which becomes (using hexadecimal 11alues):
%77 %77 %77 %2£ %68 %6 F %64 %64 %65 %72 %2E %63 %6 F %2E %75 %6B
h d d k


(Note: the% sign is used to denote that hexadecin1al is being used.)
1.6 Use of the hexadecimal system

Activity 1.9
Using the ASCII rnde table (Figure 1.7) convert the following URL~ into the equivalent
hexadecimal:
a www.de.org.uk
b www.de.org.uk/computer_sdence
c httpsJ/INvwi.hodder.co.uk
d www.HodderEducation .co.uk
e http://www.ucles.ac.uk/computing.htm

Sometimes the hexadecimal addresses arc used in the address of files or web pages
as a security feature. It takes longer to type in the URL using the hexadecimal
codes, but it has the advantage that you are unlikely to fall into the trap of
copying and pasting a 'fake' website address.

1.6.5 Assembly code and machine code


Computer memory can be referred to directly using machine code or assembly
code. This can have many advantages to program developers or when carrying
out troubleshooting.
Machine code and assembly code are co\·ered in much more derail in Chapter 7;
here we are simply interested in how hexadecimal fits into the picrnre.
Using hexadecimal makes it much easier, faster and less error prone to write
code compared to binary. Using true machine code (which uses binary ) is \·ery
cumbersome and it takes a long time to kL-y in the values. It is also very easy to
mistype the digits in a 'sea of ls and Os'. Here is a simple example:
STO FFA4 (assembly code )

A5E4 FFA4 (machine code using hexadecimal \lalu cs)

1010 01011110 0100 1111 1111 1010 0100 (machine code using binary)
,\lachine code and assembly code are examples of low-level languages and are
used by software dL·velopers when producing, for example, computer games. As
you will find in Chapter 7, although they look cumbersome, thL-y ha\·e many
advantages at the development stage of software writing ( especially when trying
to locate errors in the code ).
Communication and internet technologies

2.1 Introduction
When data is se nt from one device to another, it is important to consider how
that data is transmitted. It is also important to ensure that the data hasn't bee n
changed in any way.
The internet has now become an integral part of all of our li\·es. This chapter
will consider some of the important technologies going on in the background
whic h support the internet.

2.2 Data transmission


Data transmission can be either over a short distance ( for example, from
co mputer to printer) or over longer distances (for example, over a telephone
network ). Esse ntiall y, three factors need to be considered when transmitting
data (each factor has to be agreed by both sender a nd receiver for this to work
without error):
• the direction of the data transmission (i.e. in one direction only or in both
directions)
• the method of transmission (how many bits arc sent at the same time )
• the method of synchronisation between the two devices.

2.2.1 Simplex, half-duplex and full-duplex ©


S IMPLEX DATA TRANSMISSION is in one direction only (i.e. from sender to receiver ).
Example: data being sent from a computer to a printer.
HALF· DUPLEX DATA TRANSMISSION is in both directions but not at the same time
(i.e. data can be sent from 'A' to 'B' or from 'B' to 'A' along the same line, but
not at the same time ). Example: a phone conversation between two people where
only one person speaks a t a time .
FULL·DUPLEX DATA TRANSM ISSION is in bothdirectiom sim11/taneously (i.e. data
can be sent from 'A' to ' B' and from 'B' to 'A' along the same line, both at the
same time) . Example: broadband connection on a phone line.

2.2.2 Serial and parallel data transmission ©


SERIAL DATA TRANSMISSION is when data is sent, 011e bit at t1 time, over t1 single
wireorcht1nnel (bits arc se nt one after the other in a single stream).

Figure2.1


( Note: bits can be transmitted as simplex, half-duplex or full -dupl ex.)
2.2 Data transmission

This method of data transmission works well o\·er long distances. However, data
is transmitted at a slower rate than parallel data transmission. Since only one wire
or channel is used, there is no problem of data arri\'ing at its destination out of
synchronisation.
An example of its use is sending data from a computer to a modem for
transmission over a telephone line.
PARAILBL DATA TRANSMISSION is when sevem/ bits of dntt1 (umal/y 1 byte) are
sent down several wires 01' channels at the same time; one wire or channel is used
to transmit each bit.

I-· I l-~-1~;,£~
Figur• 2.2 ... ;;::=,,p
(Note: bits can be transmitted as simplex, half-duplex or full -duplex. ) •
This method of data transmission works very well o\·er short distances ( over
longer distances, the bits can become 'skewed' - this means they will no longer be Figure 2.3 R;bbooronnector
synchronised ). It is, howe\·er, a faster method of data transmission than serial.
An example of its use is when sending data to a printer from a computer using a
ribbon connector.

Activity 2.1
Describewhatisme,mtby:
a serial, hatl-duplexdatatransmission
b parallel,full-duplexdatatransmiOOn
c serial,simplexdata trammission

A common use for serial data transmission is discussed in Section 2.2.4 (Universal
Serial Bus (USB )).
Parallel data transmission is used in the internal electronics of the computer
system. The pathways benveen the CPU and the memory all use this method
of data transmission. Integrated circuits, buses and other internal components
all use parallel data transmission because of the need for high speed data transfer.
The use of8 -bit, 16-bit, 32-bit and 64-bit buses, for example, allow much faster
data transmission rates than could be achieved with single channel serial data
transfer. An internal clock is used to ensure the correct timing of data transfer;
it is essentially synchronous in narnre (see Section 2.2.3 ) and the short distances
between components mean that none of the issues described earlier have any real
impact on the accuracy ofthe data.
Chapter 4 covers the internal architecrnre of computer systems (including the
role of buses ) and this should be read in conjunction with the information given
above.

2.2.3 Asynchronous and synchronous data transmission


AsYNCH RONOUS DATA T RANSMISSION refers to data being transmitted in an agreed
bit pattern. Data bits ( ls and Os) arc grouped together and sent with CONTROL
2 COMMUNICATION AND INTERNET TECHNOLOGIES

1,tartbit 1, I O 1, 1, 1, 1, I O I O 1, 1, 1, I O 1, I O 1, I O Isiopbit I
cootrol bit
Figu,.2.4
This means that the recei\·er of the data knows when the data starts and when it
ends. This prevents data becoming mixed up; without these control bits, it would
be in1possible to separate groups of data as they arrived.
SYNC HRONOUS DATA TRANSMISSION is a continuous stream of data (unlike
asynchronous data which is sent in discrete groups). The data is accompanied by
timing signals generated by an internal clock. This ensures that the sender and
recei\'cr are synchronised with each other.
The recei\'ercounts how many bits ( l s and Os ) were sent and then reassembles
them into bytes of data. The timing must be \·ery accurate here since there arc
no control bits sent in this type of data transmission. H owe\'er, it is a faster
data transfer method than asynchronous and is therefore used where this is an
important issue (for example, in network communications).

2.2.4 Un iversa l Seria l Bus (USB)


1l1e UNIVERSAL SERIAL Bus (USB) is an asynchronous serial data transmission
method. It has quickly become the standard method for transferring data between
a computer and a number of devices. Essentially, the USB cable consists of:
• a four-wire shielded cable
• two of the wires arc used for power and the earth
• two of the wires are used in the data transmission.
When a de\'ice is plugged into a computer using one of the USB ports:
• the computer automatically detects that a device is present (this is due to a
small change in the \'oltagc level on the data signal wires in the cable ) Figu,. 2.5 use cable
• the de\'ice is automatically recognised, and the appropriate DEVICE DRIVER is
loaded up so that computer and de\'ice can communicate effectively
• if a new device is detected, the computer will look for the de\'ice driver which
matches the dt.·\'ice; if this is not available, the user is prompted to download
the appropriate software.
Even though the USB system has become the industrial standard, there arc still a
number ofbenefits (/ ) and drawbacks (x) to using this system:

Oevkespluggedintolhe«rnputera,reaotomabcally
detected;de,,;ced,iv,,.-,a,reautomaticallyuploaded
Thero,mec!OfScanonlyfitonew~:thisp,'-"'enls Themaximumcablelenglhisp,esentlyabootS
inror,ectconnectionsbeingmade metres
Thishasbecomethe indllSt,y,tan,fa,d;thismeans
thatcoosidefablesuppo,tisava ilabletousers
Severaldiffe,entdatatransmissioo,atesare Thep,esenttransmissioo,ateislimitedtoJessthan
supported 500megabil5Jll'fsecood
2.3 Error<hecking methods

2.3 Error-checking methods


Following data transmission, there is always the risk that the data has been
corrupted or changed in some way. This can occur whether data is being
transmitted over short distances or o\'er long distances.
Checking for errors is important since computers aren't able to check that text
is correct; they can only recognise whether a word is in their built-in dictionary or
not. Look at the following text:
Can you racd tihs?
' I cnduo't bvleicc taht I culod aulaclty uesdtannrd waht I was rdnaieg.
Unisg the icndeblirc pweor of the hmuan mnid, aocdcrnig to rscccrah
at Cmabridgc Uincrvtisy, it dseno't mttaer in waht oderr the ltercts in a
wrod are, the olny irpoamtnt tihng is taht the frsit and lsat ltteer be in the
rhgit pclae. The rsct can be a raotl mscs and you can sit!] racd it whoutit a
pbocrlm.
Tihs is bucscac the huamn mnid dcos not racd crvcy lttccr by istlcf, but
the wrod as a wlohc.
Aaznmig, huh? Yeah and I awlyas tghhuot slclinpg was ipmorantt! Sec if
yuor fdrcins can racd tihs too'
(From an unknown source at Cambridge University)
Whilst you probably had little problem understanding this text, a computer
would be unable to make any sense of it.
This is why error checking is such an important part of computer technology.
This section considers a number of ways tliat can be used to check for errors so
that you don't end up with text as shown in the example above!
A number of methods exist which can detect errors and , in some cases, actually
correc t tl1e error. The methods covered in tl1is section arc :

• parity checking
• automatic repeat request (ARQ)
• checksum
• echo checking.

2.3.1 Par ity check ing @


PARITY C H ECKING is one method used to check whether data has been changed or
corrupted following transmission from one device or medium to anotl1er device
or medium.
A byte of data, for example, is allocated a PA RITY BIT. This is allocated before
transmission takes place. Systems that use EVEN PA RITY ha\·e an even number of
1-bits; systems that use ODD PA RITY have an odd number of 1-bits.
Consider tl1e following byte:

p,,<itybit
Figur•2.6
2 COMMUNICATION AND INTERNET TECHNOLOGIES

If this byte is using even parity, then the parity bit needs to be O since there is
already an even number of I -bits (in this case, 4 ).
If odd parity is being used, then the parity bit needs to be I to make the
number of I -bits odd.
Therefore, the byte just before transmission would be:
either(even parity)

parjtybit
Rgu,.2.7

or (odd parity)

parjtybit
Rgu,.2.8

Before data is transferred, an agreement is made between sender and recei\·er


regarding which of the two types of parity are used. This is an example of a

Activity 2.2
Findtheparitybitsloreadiolthelollowingbytes:
a 1101101 eveoparjtyused
b 0001111 even parity used
c 0111000 even parity used
d 1110100 oddparjtyused
odd parity used

If a byte has been transmitted from 'A' to 'B', and even parity is used,
an error would be flagged if the byte now had an odd number of I-bits at
the recei\'er'send.

Examp le 1@

Rgu,.2.9

In this case, the receiver's byte has three I -bits, which means it now has odd
parity whilst the byte from the sender had even parity ( four I-bits). This clearly
means an error has occurred during the transmission of the data.
The error is detected by the computer recalculating the parity of the byte sent.
If c\'cn parity has been agreed between sender and recei\·er, then a change of
parity in the received byte indicates that a transmission error has occurred.
2.3 Error<hecking methods

Activity 2.3
Whichofthefollowingbyteshaveanerrorfollowingdatatransmission?
a 11101101 even parity used
b 01001111 even parity used
c 00111000 even parity used
d 11110100 odd parity used
odd parity used
In each case where an error occurs, can you work out which bit is incorrect?

Namrally, any of the bits in Example 1 could have been changed leading to
a transmission error. Therefore, e\·en though an error has been flagged , it is
impossible to know exactly which bit is in error. (Your last answer in Activity 2.3
should have been 'NO' since there isn't enough information to determine which
bit has been changed. )

0 One of the ways around this problem is to use PARITY BLOCKS. ln this
method, a block of data is sent and the number of 1-bits are totalled horizontally
and vertically (in other words, a parity check is done in both horizontal and
vertical directions ). As Example 2 shows, this method not only identifies that an
error has occurred but also indicates where the error is.

Examp le 2 @
In this example, nine b)'tes of data ha\·e been transmitted. Agreement has been
made that even parity will be used. Another byte, known as the PARITY BITE,
has also been sent. This b)'te consists entirely of the parity bits produced by the
\'ertical parity check. The parity b)'te also indicates the end of the block of data.
The following table shows how the data arri\·ed at the recei\'ing end:

byteB 0
byte9 0
parity

"'~
A carefid srudy of Table 2.2 shows the following:
• byte 8 (row 8 ) has incorrect parity (there are three 1-bits)
• bit 5 (column 5 ) also has incorrect parity (there are five 1-bits).
2 COMMUNICATION AND INTERNET TECHNOLOGIES

First of all, the table shows that an error has occurred following data transmission.
Secondly, at the intersection of row 8 and column 5, the position of the
incorrect bit value (which caused the error) can be found.
This means that byte 8 should have the value:

Figure2.10

which would also correct column 5 giving an even vertical parity ( now has four
1-bits ).
This byte could therefore be corrected automatically as shown above, or an
error message could be relayed back to the sender asking them to retransmit the
block of data.
One final point: if two of the bits change value following data transmission,
it may be impossible to locate the error using the above method. For example,
using fa:ample l again:

Figu re2 .11

This byte could reach the destination as:

Figure2.12

Figu re2 .13

Figure2.14

All three are clearly incorrect; but they have retained even parity so this wouldn't
have triggered an error message at the receiving end. Clearly we need to look
at other methods to complement parity when it comes to error checking
transmitted data.
2.3 Error<hecking methods

Activity 2.4
The following block of data was received after transmission from a remote computer; odd parity
beingusedbybothsenderandreceiver.Oneofthebitshasbeeochangedduringthetransmission
stage. LDG1tewherethiserrorisands.uggestamrrectedbyte value

byte1 0
byte2 1
byte3 1
byte4 0
bvt.5 1
bvte6 1
bvte7 0
bvte8 0
l bvte9 O
parity
S,w

2.3.2 Automatic Repeat Request (ARO)


Aurm,IATIC REPEAT REQuEIT (ARQ) is another method used to check whether
data has been correctly transmitted.
It uses an ACKNOWLEDGEMENT (a message sent by the receiver indicating that
data has been received correctly) and n1,rnour (this is the rime allowed to elapse
before an acknowledgement is recei\·ed ).
If an acknowledgement isn't sent back to the sender before rime out occurs,
then the message is automatically resent.

2.3.3 Checksum ®
CHECKSUM is another way to check if data has been changed or corrupted
Oividethesum,X.of
following data transmission. Data is sent in blocks and an additional value, thebyte,by2S6
the checksum, is also sent at the end of the bloc.k of data.
To explain how this works, we will assume the checksum of a block of data
is I byte in length. This gives a maximum value of28 - 1 (i.e. 255 ). 111e value Roondtheanswer
downtothenea,est
0000 0000 is ignored in this calculation. Example 3 explains how a checksum is wholenumbef.Y
generated.

Examp le 3
If the sum of all the bytes in the transmitted block of data is<• 255, then the
checksum is this value.
H owever, if the Slllll of all the brt:es in the data block> 255, then the checksum Cakulatethe
is found using the simple algorithm in Figure 2.15. ciffereoce(X - Z)

Suppose the value ofX is 1185, then tracing through the algorithm , we get:
X - 1185 Thi,valuei,the
checksum
1 1185/256 - 4.629
2 Rounding down to nearest whole number gives Y - 4 Figure 2.15
3 Multiplying br 256 gives Z - Y • 256 - 1024
4 The difference (X - Z ) gives the checksum: ( ll85 - 1024) - 161
5 This gives the checksum - 16 1
2 COMMUNICATION AND INTERNET TECHNOLOGIES

When a block of data is about to be transmitted, the checksum for the bytes is
first of all calculated. This value is then transmitted with the block of data. At the
recei\'ing end, the checksum is recalculated from the block of data received. This
calculated value is then compared to the checksum transmitted. If they are the
same value, then the data was transmitted without any errors; if the \'alues are
different, then a request is sent for the data to be retransmitted.

Activity 2.5
Cakulate the chedsum for blocks of
datawiththefollowingbytesums
, 148
b 905
c 14S0
d 4095

2.3.4 Echo check


With ECHO CHECK, when data is sent to another device, this data is sent back
again to the sender. The sender compares the two sets of data to check if any
errors occurred during the transmission process.
As you will ha\'e no doubt worked out, this isn't \'ery reliable. If the two sets
of data are different, it isn't known whether the error occurred when sending
the data in the first place, or if the error occurred when sending the data back
for checking!
H owe\·er, if no errors occurred then it is another way to check that the data
was transmitted correctly.

2.4 Internet t echno logies


TI1e internet is a world -,vide system of computer nenvorks and computers. All
computers attached to the internet can communicate with each other providing
a number of rules and protocols are adhered to.

2.4.1 Internet Service Provider (ISP)


Each user makes use of an INTERNET SERVICE PROVIDER ( ISP ); tl1ese are
companies that pro\'ide the user with access to the internet. A monthly fee is
usually charged for tills service. The ISP will set up a user account which will
contain a username and a password; most ISPs also gi,·e the user an email address.
Before ISPs became crnrunon in the 1990s, internet access was usually limited
to users who were part of a miiversity or a gO\·ernment agency.

2.4.2 Internet Protocol (IP) Address


Each device on the internet is gi\'en a uniqu e address known as tl1e INI"ERNIIT
PROTOCOL ( IP ) ADDRESS. This is a 32 -bit number which is usually written in the
form:
109.108.158.1
A home computer is given an IP address when it connects to the internet. This is
assigned by the ISP and is unique for that particular internet session. The only IP
addresses tl1at remain fairly unchanged are web ser\'ers.
2.4 Internet technologies

An I P address can be used instead of typing in the full URL. For example:
hnp://109. 108.158.1
would take you straight to the device corresponding to this address.

IP addresses and MAC add resses


You will recall the term MEDIA ACCESS CONrROL (MAC) ADDRESS from Chapter l.
This is a unigue number that identifies a device connected to the internet. So
what is the difference between an IP address and a ,\.IAC address? The IP address
gives the location of a device on the internet, whereas the MAC address identifies
the device connected to the internet.
You can think of the IP address as the address of the house you live in ( it will
have some unique way of identifying it, such as a JX)St or zip code). Using this
example, the MAC address can be thought of as a way of uniquely identifying
each person living in that house. It is possible to move house (so your IP address
will change) but the same people will be living in the new house ( so their MAC
addresses will remain unchanged ).

2.4.3 HyperText Mark-up Language (HTML)


H YPERTEXT MARK-UP LANGUAGE (H TML) is used when writing and
de\·eloping web pages. HTML isn't a programming language but is simply a
mark-up language. A mark-up language is used in the processing, definition and
presentation of text (for example, specifying the colour of the text).
HTML uses <tags> which are used to bracket a piece of code; for example,
<td> starts a standard cell in an H TML table, and </td> ends it. 'Nhatever is
between the two tags has been defined. H ere is a short section of H TML code:
c:tr>
c:td>c:hl>Small carc:/hJ>
c:hl>Used car salesc:/hl>
c:h2>Ca rs from $500c:/h2>
c: br >c:h2>Cas h sales onlyc:/h2>c:/td>c:/br>
c:/tr>

c:colgroup>
c:col span•"2" style•"background-color,red">
c:col style•"background-color :yellow">

HTML st ru ct ure and prese ntati on


\\'hen writing H TML code, it is very imixirtant to realise that there is a difference
between the structure and the presentation.
Sr&ucruRE is the essential part of the H TML document; it includes the
se mantics (meaning ) and strucrnral mark-up of the document.
PRESENTATION is the style of the document; i.e. how the document will look
(or even sound ifit includes multin1edia elements).
These two features must be kept separate throughout the designing of a
web page. At the end of the design process, the author should have an HTML
document (which contains the structure and the actual content) and a separate
css (CASCAD ING STYLE SH EIIT) file. The css file will contain t.·verything to control
the acrnal presentation ofthe web page.


2 COMMUNICATION AND INTERNET TECHNOLOGIES

Some of the <tags> used to create a css file have been shown already in the
HTML example shown abo\·e . The following section shows an example ofhow
these <tags> can be used to create a stylesheet called example2 . css. This is
then used in a web page document. The tags (hl, h3 and p ) all define how the
document will look when this css file (stylesheet) is attached.

~r'"--"'"-"'f<;io,, ..... -r,.;.i~E,:1.,..,.-,......


lcalo.aia!~uark
(eolo"'f:r::~~ifji;;7rlf:

Figu ,.2.16 Thisshow,:howlhecssfile (examp'el.css)isc,eatedfllf useinthe


documentbelow;h1.h3andphaveall beendefined. sowhenthefileisattached
below.awebbmwserknow,:howtodisplaythi,webpage

Figu ,.2.17

2.4.4 Hypertext transfer protocol (http)


HYPERTEXT TRANSFER PROTOCOL ( Hrrr ) is a se t of rules th at must be obeyed
when transferring files across the internet. \Vhen some form of security ( e.g. SSL
1

~;:~fi:i::~:: :::7~ti;~~~~:es:~las ::l ~;l:s s~: : : :~:~ ~ : : ~::~:s at:e~t1:::p

refers to http over i; ecure. It is slower to use https than http; https is usually only
adopted where sensit.i\·e or private data is being transferred across the .internet.

2.4.5 Web browsers


A WBB BROWSBR is software which allows a user to display a web page on their
computer screen . Web browsers interpret or translate the HTML code from
websites and show the result of the translation. This can often be in the form of
videos, images or sound . Most web browsers share the following features:
• they have a H OME page
• they have the ability to store a user's fu\·ourite websites/pages
• they keep a history of the websites vis ited by the user
• they give the ability to go backward and forward to websites opened.
2.4 Internet technologies

Users can either dick on a link, such as \.\'W'\','.hoddcreducation.co.uk/igcse or


they can type in the uniform resource locator (U RL ) manually.
The web browser will break up the URL into three parts:

http:/ /www.hoddereducation.eo. uk/i gcsc_comp11ter_scien ce

the protocol
used {i.e (o ften the
http) web page)

The web browser translates the web server name into an IP address (see Section
2.4.2) which is part ofthe URL. The HTML code is remrned and is shown as a
correctly formatted page on the computer screen . It is also (X)SSible th at cookies
may be sent from the web browser to the web se rver when the code is executed.
( Note: please refer to Section 8 .3 for more information about the use of cookies.)


® Logic gates and logic circuits

lnthischapteryouwilllearnabout:
e logk:gates
e truthtilbles
e logkdrcuit1
e useolBooleanalgebra

3.1 Introduction
Electronic circuits in computers, many new memories and controlling devices
are made up of thousands of LOGIC GATES. Logic gates take bi.nary inputs and
produce a binary output. Several logic gates combined together form a LOG IC
C I RCUIT and these circuits are designed to carry out a specific function.
The checking of the output from a logic gate or logic circuit is done using
a T RlITH TABLE .
This chapter will consider the function and role oflogic gates, logic circuits
and truth tables. Also a number of possible applications of logic circuits will
be considered. A reference to BooL EAN ALG EBRA will be made throughout the
chapter, but this is really outside the scope of this textbook. H owever, Boolean
algebra will be seen on many logic gate websites and is included here for
completeness.

3.2 Logic gates ®


Six different logic gates will be considered in this chapter:

=D-
----[>-
NOT gate ANO gate

=D- =D-
0 R gate NANO gate

=D- =D-
NOR gate XOR gate
Figu,.3.1 Logicgate,ymbols

3.3 Trut h ta bles


Truth tables arc used to trace the output from a logic gate or logic circuit. The
NOT gate is the only logic gate with one input; the other five gates ha\'c two
inputs.
\\'hen constructing truth tables, all possible combinations of ls and Os which
can be input arc considered. For the NOT gate (one input) there are only 21 (2 )
possible binary combinations. For all other gates (two inputs), there are 22 (4 )
possible binary combinations.
For logic circuits, the number of inputs can be more than 2; for example
three inputs give a possible 23 (8 ) binary combinations. And for four inputs,
the number of possible binary combinations is 2'4- (16). It is clear that the number
of possible binary combinations is a multiple of the number 2 in C\'ery case.
3.4 The function of the logic gates

To summarise in table form:


Ta ble 3.1Truthtablesla< two threeandtou,inputs
Inputs Inputs Inputs

I','---,~·~~ ~~-tC-
' ~-t-'-----i

3.4 The function of the logic gates


3.4.1 NOT gate
A--[>-,
Figur• 3.2

Description: Truth table: How to write this:


The output, X, is l if: X - NOT A (logic notation)
Input Output
the input, A, is 0 X- a (Boolean algebra)
A '

3.4.2 AND gate

Figur• 3.3

Description: Truth table: How to writ e this:


The output, X, is 1 if: X - A AND B (logic notation)
Inpu ts Output
both inputs, A and B, are 1 X- a · b (Boolean algebra)
' '
3 LOGIC GATES AND LOGIC CIRCUITS

3.4.3 OR gate

Figu,.3.4

Descripti on: Truth table: How to write this:


TI1coutput, X, is 1 if: X - A ORB (logic notation )
either input, A or B, is 1 X - a+ b (Boolean algebra)

3.4.4 NAND gate (NOT AND)

:=O-x
Figu,.3.5

Description: Truth table: How to write this:


TI1coutput, X, is 1 if: X - A NAND B (logic notation)
input A AND input B X- ~ (Boolean algebra )
arc NOT both I

3.4.5 NOR gate (NOT OR)

Figu,.3.6

Descripti on: Truth table: How to write this:


TI1coutput, X, is 1 if: X - A NOR B (logic notation )
neither input A nor X - a+D (Boolean algebra )
input Bis 1
3.5 Logic circuits

3.4.6 XOR gate

:=D-x
Figur• 3.7

Desc ripti o n: Truth t a bl e: How t o w rit e thi s:


The output, X, is l if: X - A XOR B (logic notation)
Inputs Output
(input A is 1 AND input BisO) X -(a · 6 ) + (i · b) (Boolean algebra )
0 X
OR (Note: this is sometimes wrinen
(inputAisOANDinputBis 1) as: (a+b) · ~ )

Activity 3.1
FindoutwhyX:(a,D)+(ii,b)and(a+b},a--:--obothrepresentthesamelogk:gate

( Note: the three symbols in the Boolean algebra ha\·e the following meaning:
represents the AND operation
+ represents the OR operation
a bar abo\·e the letter, e.g. ii, represents the NOT operation. )

3.5 Logic ci rcuits


\\'hen logic gates are combined together to carry out a particular function,
such as controlling a robot, they form a logic circuit.
The output from the logic circuit is checked using a truth table. There now
follows three examples which show:
• how to produce a truth table
• how to design a logic circuit from a gi\·en logic statement/Boolean algebra
• how to design a logic circuit to carry out an actual safety function.

3.5.1 Example 1 ®
Produce a truth table for the following logic circuit (note the use of • at
junctions):

Figur• 3.8
3 LOGIC GATES AND LOGIC CIRCUITS

There arc three inputs to this logic circuit, therefore there will be eigh t possible
binary values which can be input.
To show step-wise how the truth table is produced, the logic circuit has been
split up into three parts and intermediate values arc shown as P, Q and R.

Part 1
This is the first part of the logic circuit; the first task is to find the intermediate
valucs P andQ.

Figu,.3.9

TI1e value of P is found from the AND gate where the inputs arc A and B.
TI1cvaluc ofQ is found from the NOR gate where the inputs arc B and C.
An intermediate truth table is produced using the logic function descriptions
in Section 3.4.

Input values OutputvaluH

Part 2
111c second part of the logic circuit has P and Q as inputs and the intermediate
output, R:

Figu,.3.10


3.5 Logic circuits

This produces the following intermediate truth table. (Note: even though there
are only two inputs to the logic gate, we ha\·e generated eight binary values in
part 1 and these must all be used in this second truth table. )

Inputs Output

Q "

Part 3
The final part of the logic circuit has Rand C as inputs and th e final output, X:

Figur• 3.11

This gi\·es the third intermediate truth table:

Inputs

Putting all three intermediate truth tables together produces the final truth table
which represents the original logic circuit:

lnputvaluH
3 LOGIC GATES AND LOGIC CIRCUITS

TI1e intermediate \'alues can be left out ofthe final truth table, but it is good
practice to lea\'e them in until you become confident about producing the truth
tables. The final truth table would then look like this:

lnputvalu.. Output

Activity 3.2
Producetruthtablesforeachofthefollowinglogiccircuit"i.Youareadvisedtosplitthemupinto
intermediatepartstohelpeliminateerrors.

Figure3.1 2
3.5 Logic circuits

3.5.2 Examp le 2 e
A safety system uses three inputs to a logic circuit. An alarm, X, sounds if input
A represents ON and input B represents OFF; or if input B represents ON and
inputCrepresentsOFF.
Produce a logic circuit and truth table to show the conditions which cause
the output Xtobe 1.
The first thing to do is to write down the logic statement representing the
scenario in this example. To do this, it is necessary to recall that ON - 1 and
OFF - 0 and also that O is usually considered to be NOT 1.
So we get the following logic statement:
(Aa1AND8aNOT1) OR (B•1ANDCaOOT1 )

Th,J.,.rn
moo~ct,,.., I
the OR gate
I

Figur• 3.17

Note: this statement can also be written in Boolean algebra as:


1• · SJ. (b . ,)
3 LOGIC GATES AND LOGIC CIRCUITS

The logic circuit is made up of three parts as shown in the logic statement. \Ve
will produce the logic gate for the first part and the third part. Then join both
parts together with the OR gate.

Figure3.18

Now combining both parts with the OR gate gi\'es us:

Figure3.19

l11ere are two ways to produce the truth table:


• trace through the logic circuit using the method described in Example 1
(Section 3.5.1 )
• produce the truth table using the original logic statement; this second method
has the advantage that it allows you to check that your logic circuit is correct.
We will use the second method in this example:

Inputs Output
B (A:1 AND 8:NOT 1) (8:1 AND C=NOT 1) X

(Note: it is optional to leave in the intermediate values or to remm·e them giving


a four-column truth table with headings: A, B, C, X. )
3.5 Logic circuits

Activity 3.3
Orawthelogiccircuitsandcompletethetruthtableslorthefollowinglogicstatementsand
Boolean algebra statements:
a X: 1 if{A: 1 ORB: 1)0R(A:OAN08 = 1)
b Y = 1 if{A = OAND B = O)AND{B = 0 OR C = 1)
c T = 1 if (switch K is ON or switch Lis ON) OR (switch K is ON and switch Mis OFF) OR (switch
Mis ON)
d X:(a.b)+(b.c}
a R = 1 if (switdi A is ON and switch 8 is ON) ANO (switch 8 is ON or switch C is OFF)

3.5.3 Exa m p le 3
A wind rnrbine has a safety system which uses three inputs to a logic circui t.
A certain combination of conditions results in an output, X, from the logic circui t
being cciual to 1. \Vhcn the value ofX - 1 then the wind mrbine is shut down.
The following table shows which parameters are being monitored and form
the three inputs to the logic circuit.

Parameter Binaryvalu • D-riptionofcondition


d- ription

turbinespel'd

bearingtemperature T

<a120kph
\Mndvekx:ity
>120kph

The output, X, w ill ha\·e a value of l if any of the following combination of


conditi ons occur:
• either mrbine speed< • 1000 rpm and bearing temperature> 80°C
• or mrbine speed > I OOO rpm and wind velocity > 120 kph
• or bearing temperamre <• 80°C and wind velocity> 120 kph.
D esign the logic circuit and complete the truth table to produce a value ofX - 1
when any of the three conditions above occur.
This is a different type of problem to those covered in Examples l and 2.
This time a real situation is g iven and it is necessary to convert the information
into a logic statement and then produce the logic circuit and truth table. It is
ad\~sable in problems as complex as this to produce the logic circuit and truth
table separately (based on the conditions given ) and then check them against each
o ther to see ifthere are any errors.

Stage 1
The first thing to do is to convert each of the three statements into logic
statements. Use the information given in the table and the three condition
statements to find how the three parame ters, S, T and W, are linked. We usually
look for the key words AND, OR and NOT when converting actual statements
into logic.


3 LOGIC GATES AND LOGIC CIRCUITS

\\'e end up with the following three logic statements:


i turbine speed <• I 000 rpm and bearing temperature > 80°C
logic statement: (S - NOT l AND T - 1 )
i turbine speed > 1000 rpm and wind velocity> 120 kph
logic statement: (S - 1 AND W - 1 )
iii bearing temperature <• 80°C and wind velocity > 120 kph
logic statement: (T - NOT 1 AND W - 1 )

Stage 2
This now produces three intermediate logic circuits:

Figu,.3.20

i ! ====O-
Figu .. 3.21

Figu,.3.22

Each of the three original statements were joined together by the word OR. Thus
we need to join all of the three intermediate logic circuits by two OR gates to get
the final logic circuit.
We will start by joining (i) and (ii ) together using an OR gate :

Figu,.3.23


3.5 Logic circuits

Finally, we connect the logic circuit in Figure 3.23 to Figure 3.22 to obtain
theammrer:

Figur• 3.24

The final part is to produce the truth table. We will do this using the original
logic statement. This method has the bonus of allowing an extra check to be
made on the logic circuit in Figure 3 .24 to see whether or not it is correct. It is
possible, howe\'er, to produce the truth table straight from the logic circuit in
Figure 3.24.
There were three parts to the problem, so the truth table will first evaluate each
part. Then, by applying OR gates, as shown below, the final value, X, is obtained :
i (S - NOTIANDT - 1)
ii (S - 1 ANDW - 1)
iil (T - NOT I ANDW - 1)
We find the outputs from parts (i) and (ii) and then OR these two outputs
together to obtain a new intermediate, which we will label part (iv ).
We then OR parts (iii) and (i\') together to get the \'alue ofX.

lnouts Outcut
T (i)(S:NOT 1 (ii)(S:1AND (iiQ(T:NOT 1 (iv) X
ANDT: 1) W: 1) ANDW: 1)
3 LOGIC GATES AND LOGIC CIRCUITS

Activity 3.4
Twoscenariosaredesc:ribedbelow. lne.Khu11e,producethelogiccircuitandcompleteatruth
tabletorepreseotthesc:enario
iiAchemicalprocessisprotectedbyalogicdrcuit.Therearethreeinputstothelogiccircuit
representing key parameters in the chemical process. An alarm, X, will give an output value
of1 dependingoncertainconditionsinthechemicalprocess. The following table describes
theprocessconditionsbeingmonitored:

Puam•t..rdHcription Parametu Binarvvalu• o -riptionofcondition


che mkalrea<lionrate O rea<lion,at e <40mol/llsec

process tem perature

Analarm,X,willgeneratethevalue 1 if:
either
reactionrate<40moWsec

concentration> 4 mol ANO temperature> 115°(

reaction rate>= 40 moWsec ANO temperature> 115°(


b Apo1Nerstationhasasaletysystemcontrolledbyalogiccircuit. Threeinputstothelogic
circuit determine whether the output, S, is 1. When S = 1 the power !ilation shuts down .
Thefollowingtabledescribestheconditionsbeingmonitored

Param.ierdHcription Parame tu Binaryvalu• D-riptionofcondition


gas temperature O astemperature <:160"(

reactor pressure

wate r temperature water te mperature <:120"(

Output,S,willgenerateavalueofl,if
either
gas temperature> 160'C AND water temperature<= 120"C

gas temperature<= 160'CANDreactorpressure> 10bar

water temperature> 120°CANDreactorpressure> 10bar

3.6 Logic circuits in the real world


Anybody with an electronics background who is reading this chapter will be aware
that the design of logic circuits is considerably more complex than has been described.
This chapter has described in detail some of the fundamental theories used
in logic circuit design. This will give the reader sufficient grounding to cover all
existing ( l )GCSE and O level syllabuses. H owc\'cr, it is worth finally discussing
some of the more advanced aspects oflogic circuit design.
Electronics companies need to consider the cost of components, case of
fabrication and time constraints when designing and building logic circuits.
3.6 logic circuits in the real world

\\'e will mention two possible ways electronics companies can review logic
circuit design:
1 One method is to use 'off-the -shelf' logic units and build up the logic circuit
as a number of'building blocks'.
2 Another method im·olves simplif)ing the logic circuit as far as possible; this may
be necessary where room is at a premium (e.g. in building circuit boards for use
in satellites to allow space exploration).

3.6.1 Using logic 'building blocks'


One very common 'building block' is the NANO gate . It is possible to build
up any logic gate, and therefore any logic circuit, by simply linking together a
number ofNAND gates. For example, the AND, OR and NOT gates can be
built from these gates as shown below:
The AND gate :

Figure3.25

The OR gate:

Figur• 3.26

The NOT gate:

Figur• 3.27

Activity 3.5
8ydrawingthetrutht<1bles,showthatthethreecircuitsabovecanbeusedtorepresentANO,
OR and NOT gates.
3 LOGIC GATES AND LOGIC CIRCUITS

Activity 3.6
a Show how the following logic circuit could be built using NAND gates only.
Alsocompletetruthtablesforbothlogicdrcuit1toshowthattheyproduceidentic.aloutputs

Fig ure3.28
b Show how the XOR gate could be built from NAND gates only.
c Complete a truth table for your final design to show it that it produces the !>ilme output as a
single XOR gate .

Activity 3.7
Show by drawing a truth table which single logic gate has the s.ame function as the following
logic circuit made up of NAND gates only.

Figu re3 .29

3.6.2 Simplification of logic circuits


The second method invokes the simplification oflogic circuits. By reducing the
number of components, the cost of production can be less. T his can also impro\·c
reliability and make it easier to trace faults if they occur.
The following example ( Figure 3 .30) can be simplified to a single gate. You are
asked to show how this can be done in Activity 3.8 .

Fig ure3.30

You might also like