Extracted Pages From Cambridge IGCSE Computer Science
Extracted Pages From Cambridge IGCSE Computer Science
Extracted Pages From Cambridge IGCSE Computer Science
~;~.~ 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.
~: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.
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.
( 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.
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
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
1kiim,te(1KB)
(1MB)
e(1GB)
1terabvte(1Tl!)
1nPtabvte(1P!!)
0
1.5 The hexadecimal system
Figur• 1.2
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
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 BINARY SYSTEMS AND HEXADECIMAL
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
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
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
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
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
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
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
0
1 BINARY SYSTEMS AND HEXADECIMAL
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!
Figu re 1.6
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
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:
•
1 BINARY SYSTEMS AND HEXADECIMAL
" "
.. " " "'
<: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
•
(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.
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.
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.
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).
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
• parity checking
• automatic repeat request (ARQ)
• checksum
• echo checking.
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
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:
Figure2.12
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.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
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.
c:colgroup>
c:col span•"2" style•"background-color,red">
c:col style•"background-color :yellow">
•
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.
Figu ,.2.17
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.
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.
=D-
----[>-
NOT gate ANO gate
=D- =D-
0 R gate NANO gate
=D- =D-
NOR gate XOR gate
Figu,.3.1 Logicgate,ymbols
I','---,~·~~ ~~-tC-
' ~-t-'-----i
Figur• 3.3
3.4.3 OR gate
Figu,.3.4
:=O-x
Figu,.3.5
Figu,.3.6
:=D-x
Figur• 3.7
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.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.
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
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
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
Figure3.19
Inputs Output
B (A:1 AND 8:NOT 1) (8:1 AND C=NOT 1) X
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.
turbinespel'd
bearingtemperature T
<a120kph
\Mndvekx:ity
>120kph
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
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:
Analarm,X,willgeneratethevalue 1 if:
either
reactionrate<40moWsec
reactor pressure
Output,S,willgenerateavalueofl,if
either
gas temperature> 160'C AND water temperature<= 120"C
\\'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).
Figure3.25
The OR gate:
Figur• 3.26
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.
Fig ure3.30