🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

The Cambridge IGCSE™ and O Level Computer Science series consists of a Student’s Book, Boost eBook, two Workbooks and Teacher’s Guide with Boost Subscription. Cambridge Cambridge Cambridge Cambridge Cambridge IGCSE™ and O IGCSE™ and O IGCSE™ and O...

The Cambridge IGCSE™ and O Level Computer Science series consists of a Student’s Book, Boost eBook, two Workbooks and Teacher’s Guide with Boost Subscription. Cambridge Cambridge Cambridge Cambridge Cambridge IGCSE™ and O IGCSE™ and O IGCSE™ and O IGCSE™ and O IGCSE™ and O Level Computer Level Computer Level Computer Level Computer Level Computer Science Second Science Second Science Computer Science Science Teacher’s Edition Edition Boost Systems Algorithms, Guide with Boost 9781398318281 eBook Workbook Programming and Subscription 9781398320765 9781398318496 Logic Workbook 9781398318502 9781398318472 To explore the entire series, visit www.hoddereducation.com/cambridge-igcse-computerscience Cambridge IGCSE™ and O Level Computer Science Teacher’s Guide with Boost Subscription Created with teachers and students in schools across the globe, Boost is the next generation in digital learning for schools and colleges, bringing quality content and new technology together in one interactive website. The Teacher’s Guide includes a print handbook and a subscription to Boost, where you will find a range of online resources to support your teaching. Confidently deliver the updated syllabus with scheme of work, answers for Student’s Book activities and exam-style questions, electronic solutions for programming activities in the Student’s Book and answers for both workbooks. Aid understanding with vocabulary flashcards to offer support to ESL learners. Tackle technical concepts with automated PowerPoint presentations that help students to clearly see the working and logic that underpins problem-solving for these topics. To purchase Cambridge IGCSE™ and O Level Computer Science Teacher’s Guide with Boost subscription, visit www.hoddereducation.com/ cambridge-igcse-computerscience Cambridge IGCSE™ and O level Computer Science Second Edition David Watson Helen Williams 318281_FM_CAM_IGCSE CO_SCI_i_x.indd 1 25/02/21 11:10 AM Cambridge International copyright material in this publication is reproduced under licence and remains the intellectual property of Cambridge Assessment International Education. Cambridge Assessment International Education bears no responsibility for the example answers to questions taken from its past question papers which are contained in this publication. Exam-style questions and sample answers have been written by the authors. In examinations, the way marks are awarded may be different. References to assessment and/or assessment preparation are the publisher’s interpretation of the syllabus requirements and may not fully reflect the approach of Cambridge Assessment International Education. Third-party websites and resources referred to in this publication have not been endorsed by Cambridge Assessment International Education. Acknowledgements The Publishers would like to thank the following for permission to reproduce copyright material. p.xi © pinglabel/stock.adobe.com; p.31 © adisa/Fotolia; p.85 t © md3d/stock.adobe.com; p.86 l © SergeyBitos/Shutterstock. com; p.87 © Елена Хайруллина/stock.adobe.com; p.92 © Romanchuck/ Fotolia; p.94 tl © jijomathai/stock.adobe.com, bl © Dmitriy Melnikov/Fotolia.com; p.104 © Elokua/stock.adobe.com; p.105 © Konstantin/Fotolia; p.106 tl © philipus/stock.adobe. com, bl © Marek/stock.adobe.com; p.108 b © Scanrail/stock.adobe.com; p.111 tl © Alec Romijn/Alamy Stock Photo; p.115 t © Manfred Schmidt/Fotolia.com; p.121 c © Mauro Rodrigues/Fotolia, l ©Martin Dohrn/Science Photo Library; p.123 © wpg77/ stock.adobe.com; p.127 © Engdao/stock.adobe.com; p.138 c ©iStockphoto.com/Karl Yamashita, b © jacobx/stock.adobe. com; p.139 r © Cigdem Simsek / Alamy Stock Photo; p.156 tl © Allies Interactive/Shutterstock.com; p.201 © Andrew Brown/ Fotolia; p.202 © Stanford Eye Clinic/Science Photo Library; p.230 cl © bobo1980/stock.adobe.com, r © Ocskay Mark/stock. adobe.com, bl © naka/stock.adobe.com; p.231 b © Purestock/Alamy Stock Photo; p.232 t © wellphoto/stock.adobe.com, b © Image Source/Alamy Stock Photo; p.235 © Monica Wells/Alamy Stock Photo; p.239 © tino168/Shutterstock.com; p.251 © c watman/stock.adobe.com; p.257 © Maximusdn/stock.adobe.com; p.259 tl Cambridge map, reproduced with permission from OS © Crown copyright and database rights 2021 Hodder Education under licence to OS, tr © chagpa/stock.adobe.com. t = top, b = bottom, l = left, r = right, c = centre Computer hardware and software brand names mentioned in this book are protected by their respective trademarks and are acknowledged. Scratch is developed by the Lifelong Kindergarten Group at the MIT Media Lab. See http://scratch.mit.edu Every effort has been made to trace all copyright holders, but if any have been inadvertently overlooked, the Publishers will be pleased to make the necessary arrangements at the first opportunity. Although every effort has been made to ensure that website addresses are correct at time of going to press, Hodder Education cannot be held responsible for the content of any website mentioned in this book. It is sometimes possible to find a relocated web page by typing in the address of the home page for a website in the URL window of your browser. Hachette UK’s policy is to use papers that are natural, renewable and recyclable products and made from wood grown in well-managed forests and other controlled sources. The logging and manufacturing processes are expected to conform to the environmental regulations of the country of origin. Orders: please contact Hachette UK Distribution, Hely Hutchinson Centre, Milton Road, Didcot, Oxfordshire, OX11 7HH. Telephone: +44 (0)1235 827827. Email [email protected] Lines are open from 9 a.m. to 5 p.m., Monday to Friday. You can also order through our website: www.hoddereducation.com ISBN: 9781398318281 © David Watson and Helen Williams 2021 First published in 2014 This edition published in 2021 by Hodder Education, An Hachette UK Company Carmelite House 50 Victoria Embankment London EC4Y 0DZ www.hoddereducation.com Impression number 10 9 8 7 6 5 4 3 2 1 Year 2025 2024 2023 2022 2021 All rights reserved. Apart from any use permitted under UK copyright law, no part of this publication may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying and recording, or held within any information storage and retrieval system, without permission in writing from the publisher or under licence from the Copyright Licensing Agency Limited. Further details of such licences (for reprographic reproduction) may be obtained from the Copyright Licensing Agency Limited, www.cla.co.uk Cover photo © phonlamaiphoto – stock.adobe.com Typeset by Aptara Inc. Printed in the UK A catalogue record for this title is available from the British Library. 318281_FM_CAM_IGCSE CO_SCI_i_x.indd 2 23/02/21 4:59 PM Contents Introductionv SECTION 1 COMPUTER SYSTEMS 1 1 Data representation 2 1.1 Number systems 2 1.2 Text, sound and images 25 1.3 Data storage and file compression 32 2 Data transmission 45 2.1 Types and methods of data transmission 45 2.2 Methods of error detection 54 2.3 Symmetric and asymmetric encryption 63 3 Hardware 75 3.1 Computer architecture 75 3.2 Input and output devices  88 3.3 Data storage 119 3.4 Network hardware 133 4 Software 147 4.1 Types of software and interrupts 147 4.2 Types of programming language, translators and integrated development environments (IDEs) 165 5 The internet and its uses 180 5.1 The internet and the World Wide Web (WWW) 180 5.2 Digital currency 186 5.3 Cyber security 189 6 Automated and emerging technologies 217 6.1 Automated systems 217 6.2 Robotics 230 6.3 Artificial intelligence (AI) 241 iii 318281_FM_CAM_IGCSE CO_SCI_i_x.indd 3 2/18/21 1:21 PM SECTION 2 ALGORITHMS, PROGRAMMING AND LOGIC 257 7 Algorithm design and problem solving 258 7.1 The program development life cycle 258 7.2 Computer systems, sub-systems and decomposition 260 7.3 Explaining the purpose of an algorithm 271 7.4 Standard methods of solution 272 7.5 Validation and verification 276 7.6 Test data 281 7.7 Trace tables to document dry runs of algorithms 282 7.8 Identifying errors in algorithms 285 7.9 Writing and amending algorithms 288 8 Programming 299 8.1 Programming concepts 302 8.2 Arrays 329 8.3 File handling 333 9 Databases 339 9.1 Databases 339 10 Boolean logic 356 10.1 Standard logic gate symbols 356 10.2 The function of the six logic gates 358 10.3 Logic circuits, logic expressions, truth tables and problem statements 360 Index387 iv 318281_FM_CAM_IGCSE CO_SCI_i_x.indd 4 2/18/21 1:21 PM Introduction Introduction Aims This book has been written for students of Cambridge IGCSETM Computer Science (0478/0984) and Cambridge O Level Computer Science (2210) for examination from 2023. It fully covers the syllabus content, provides guidance to support you throughout the course and helps you to prepare for examination. This book will help students to develop a range of skills, including programming, problem solving and testing and evaluation, as well as introducing them to automated and emerging technologies. Assessment The information in this section is taken from the Cambridge IGCSE and O Level Computer Science syllabuses (0478/0984/2210) for examination from 2023. You should always refer to the appropriate syllabus document for the year of examination to confirm the details and for more information. The syllabus document is available on the Cambridge International website at: www.cambridgeinternational.org There are two examination papers: Paper 1 Computer Systems Paper 2 Algorithms, Programming and Logic Duration 1 hour 45 minutes 1 hours 45 minutes Marks 75 marks 75 marks Percentage of overall marks 50% 50% Syllabus topics examined 1–6 7–10 How to use this book The information in this section is taken from the Cambridge IGCSE and O Level Computer Science syllabuses (0478/0984/2210) for examination from 2023. You should always refer to the appropriate syllabus document for the year of your examination to confirm the details and for more information. The syllabus document is available on the Cambridge International website at www.cambridgeinternational.org Organisation The content is organised into 10 chapters, corresponding to the syllabus. The content is in the same order as the syllabus. The material directly relevant to Computer Systems is in Chapters 1–6 and the material directly relevant to Algorithms, Programming and Logic is in Chapters 7–10. v 318281_FM_CAM_IGCSE CO_SCI_i_x.indd 5 2/26/21 3:59 PM INTRODUCTION Features Learning outline Each chapter opens with an outline of the subject material to be covered. In this chapter, you will learn about: ★ automated systems – the use of sensors, microprocessors and actuators in automated systems – the advantages and disadvantages of using automated systems in given scenarios ★ robotics – what is meant by robotics – the characteristics of a robot – the roles, advantages and disadvantages of robots ★ artificial intelligence – what is meant by artificial intelligence (AI) – the main characteristics of AI – the basic operation and components of AI systems to simulate intelligent behaviour. Chapter introduction A short introduction to the chapter topics and their focus. This chapter considers the hardware found in many computer systems. The hardware that makes up the computer itself and the various input and output devices will all be covered. Activity Short questions and exercises to help recap and confirm knowledge and understanding of the concepts covered. Activity 1.2 Convert the following denary numbers into binary (using both methods): a 41 d 100 g 144 j 255 m 4095 b 67 e 111 h 189 k 33000 n 16400 c 86 f 127 i 200 l 889 o 62307 Example Worked examples of technical or mathematical techniques. Example 2 A camera detector has an array of 2048 by 2048 pixels and uses a colour depth of 16. Find the size of an image taken by this camera in MiB. 1 Multiply number of pixels in vertical and horizontal directions to find total number of pixels = (2 048 × 2 048) = 4 194 304 pixels 2 Now multiply number of pixels by colour depth = 4 194 304 × 16 = 67 108 864 bits 3 Now divide number of bits by 8 to find the number of bytes in the file = (67 108 864)/8 = 8 388 608 bytes 4 Now divide by 1024 × 1024 to convert to MiB = (8 388 608)/(1 048 576) = 8 MiB. vi 318281_FM_CAM_IGCSE CO_SCI_i_x.indd 6 2/18/21 1:21 PM Introduction Find out more Short activities that go a little beyond the syllabus, for those students who have a deeper interest in the subject. Find out more Find out how buffers are used to stream movies from the internet to a device (such as a tablet). Advice As well as library Advice routines, typical IDEs These provide tips and background, and also highlight any content that is not also contain an editor, specifically covered in the syllabus. for entering code, and an interpreter and/or Links a compiler, to run the Numerous topics in Computer Science are connected together. The Links feature code. states where relevant material is covered elsewhere in the book. Link Extension For more details on Written for students interested in further study, and placed at the end of each RAM, see Section 3.3. chapter, this optional feature contains details of more sophisticated topics that are explored in the International A Level syllabus. Extension For those students considering the study of this subject The following diagram shows an artificial neural at A Level, the following section gives some insight into network (with two hidden layers) – each circle, called further study on a sub-set of machine learning called a unit or node, is like an ‘artificial neuron’: deep learning. A1 B1 Deep learning Deep learning structures algorithms in layers (input 1 A2 B2 layer, output layer and hidden layer(s)) to create an artificial neural network made up of ‘units’ or ‘nodes’, which is essentially based on the human brain (i.e. its 2 A3 B3 1 interconnections between neurons). Neural network systems are able to process more like a human and A4 B4 their performance improves when trained with more 3 and more data. The hidden layers are where data from A5 B5 the input layer is processed into something that can be sent to the output layer. Artificial neural networks are excellent at tasks that computers normally find hard. Neural networks are effective at complex visual For example, they can be used in face recognition: processing such as recognising birds, for example, by their shape and colour. There are many different sizes, colours and types of bird, and machine learning algorithms struggle to successfully recognise such a wide variety of complex objects. But the hidden layers in an artificial neural network allow a deep learning algorithm to do so. vii 318281_FM_CAM_IGCSE CO_SCI_i_x.indd 7 2/18/21 1:21 PM INTRODUCTION Summary At the end of each chapter there is a list of the main points from the chapter that you should have a good understanding of. In this chapter, you have learnt about: ✔ use of sensors, microprocessors and actuators in automated systems ✔ the advantages and disadvantages of automated systems in a number of key areas ✔ what is meant by robotics ✔ what characterises a robot ✔ the role of robots in a number of areas ✔ the advantages and disadvantages of robots in a number of areas ✔ the concept of artificial learning (AI) ✔ the main characteristics of AI ✔ expert systems ✔ machine learning. Key terms Key terms are in red throughout the book and are defined at the end of each chapter. Key terms used throughout this chapter bit – the basic computing element that is either 0 or 1, and is formed from the words Binary digit binary number system – a number system based on 2, in which only the digits 0 and 1 are used hexadecimal number system – a number system based on the value 16 which uses denary digits 0 to 9 and letters A to F error codes – error messages (in hexadecimal) generated by the computer MAC address – MAC address - standing for Media Access Control, this address uniquely identifies a device on the internet; it takes the form: NN-NN-NN-DD-DD-DD, where NN- NN-NN is the manufacturer code and DD-DD-DD is the device code IP address – IP address short for internet protocol address and identified as either IPv4 or IPv6; the IP address gives a unique address to each device connected to the internet, identifying its location hypertext mark-up language (HTML) – the language used to design, display and format web pages viii 318281_FM_CAM_IGCSE CO_SCI_i_x.indd 8 3/26/21 6:06 PM Introduction Exam-style questions Chapters 1–10 conclude with exam-style questions, to help with preparation for examination. Exam-style questions Exam-style questions 1 A software developer is using a microphone to collect various sounds for his new game. He is also using a sound editing app. When collecting sounds, the software developer can decide on the sampling resolution he wishes to use. a i What is meant by sampling resolution? ii Describe how sampling resolution will affect how accurate the stored digitised sound will be. The software developer will include images in his new game. b i Explain the term image resolution. ii The software developer is using 16-colour bitmap images. How many bits would be used to encode data for one pixel of his image? iii One of his images is 16 384 pixels wide and 512 pixels high. He decides to save it as a 256-colour bitmap image. Calculate the size of the image file in gibibytes. iv Describe any file compression techniques the developer may use. 2 The editor of a movie is finalising the music score. He will send Pseudocode and programming languages the final version of his score to the movie producer by email attachment. To succeeda inDescribe your course, you willisneed how sampling used an understanding to record the music of a particular sound clips. b The music sound clips need to undergo some form of data pseudocode syntax that will be used that will be used when studying Algorithms, Programmingcompression and Logic, before along the withmusic one editor of thecan send them following via email.programming high-level of compression, lossy or lossless, languages: Python, VB.NET or Java. Within Chapters 7 and 8,hecode Which type should use?examples are Give a justification for your answer. given using the correct pseudocode syntax and all three programming languages, c One method of data compression is known as run length each in a different encodingtext colour for clarity. (RLE). i What is meant by RLE? ▼ Table 8.4 Examples of output statements with messages ii The following image is being developed: Output the results Language print("Volume of the cylinder is ", volume) Python uses a comma Console.WriteLine("Volume of the cylinder is " VB uses & & volume) System.out.println("Volume of the Show how RLE would cylinder be used is " to produce a compressed Java uses +file for + volume); the above image. Write down the data you would expect to see in the RLE compressed format (you may assume that the It is assumed that greyaccess squarestohave an integrated a code valuedevelopment environment of 0 and the white squares (IDE) is provided by your school have forvalue a code the programming of 1). language in use but, if not, full instructions on how to download and run an IDE for each language are given in the Programming, Algorithms and Logic Workbook. 41 ix 318281_C01_CAM_IGCSE CO_SCI_001_044.indd 41 18/02/21 3:22 PM 318281_FM_CAM_IGCSE CO_SCI_i_x.indd 9 25/02/21 8:59 PM INTRODUCTION Additional support The Computer Systems Workbook and Programming, Algorithms and Logic Workbook provide additional opportunity for practice. These write-in workbooks are designed to be used throughout the course. Command words Command word What it means Calculate work out from given facts, figures or information Compare identify/comment on similarities and/or differences Define give precise meaning Demonstrate show how or give an example Describe state the points of a topic/give characteristics and main features Evaluate judge or calculate the quality, importance, amount or value of something Explain set out purposes or reasons/make the relationships between things evident/provide why and/or how and support with relevant evidence Give produce an answer from a given source or recall/memory Identify name/select/recognise Outline set out the main points Show (that) provide structured evidence that leads to a given result State express in clear terms Suggest apply knowledge and understanding to situations where there are a range of valid responses in order to make proposal/put forward considerations x 318281_FM_CAM_IGCSE CO_SCI_i_x.indd 10 2/18/21 1:21 PM SECTION 1 Computer systems Chapters 1 Data representation 2 Data transmission 3 Hardware 4 Software 5 The internet and its uses 6 Automated and emerging technologies 318281_C01_CAM_IGCSE CO_SCI_001_044.indd 1 18/02/21 3:22 PM 1 Data representation In this chapter you will learn about: ★ number systems – how and why computers use binary to represent data – the denary, binary and hexadecimal number systems – converting numbers between denary, binary and hexadecimal – how and why hexadecimal is used for data representation – how to add two positive 8-bit numbers – overflow when performing binary addition – logical binary shifts on positive 8-bit integers – two’s complement notation to represent positive and negative binary numbers ★ text, sound and images – how and why a computer represents text – the use of character sets including ASCII and Unicode – how and why a computer represents sound – sound sample rate and sample resolution – how and why a computer represents an image – the effects of the resolution and colour depth on images ★ data storage and compression – how data storage is measured – calculating the file size of an image and sound file – the purpose of and need for data compression – lossy and lossless compression. This chapter considers the three key number systems used in computer science, namely binary, denary and hexadecimal. It also discusses how these number systems are used to measure the size of computer memories and storage devices, together with how sound and images can be represented digitally. 1.1 Number systems 1.1.1 Binary represents data As you progress through this book you will begin to realise how complex computer systems really are. By the time you reach Chapter 10 you should have a better understanding of the fundamentals behind computers themselves and the software that controls them. You will learn that any form of data needs to be converted into a binary format so that it can be processed by the computer. However, no matter how complex the system, the basic building block in all computers is the binary number system. This system is chosen because it only consists of 1s and 0s. Since computers contain millions and millions of tiny ‘switches’, which must be in the ON or OFF position, they can be represented by the binary system. A switch in the ON position is represented by 1; a switch in the OFF position is represented by 0. 2 318281_C01_CAM_IGCSE CO_SCI_001_044.indd 2 18/02/21 3:22 PM 1.1 Number systems Switches used in a computer make use of logic gates (see Chapter 10) and are used to store and process data. 1.1.2 Binary, denary and hexadecimal systems The binary system We are all familiar with the denary number system which counts in multiples of 10. This gives us the well-known headings of units, 10s, 100s, 1000s, and so on: (104) (103) (102) (101) (100) 10 000 1000 100 10 1 2 5 1 7 7 Denary uses ten separate digits, 0-9, to represent all values. Denary is known as a base 10 number system. The binary number system is a base 2 number system. It is based on the number 2. Thus, only the two ‘values’ 0 and 1 can be used in this system to represent all values. Using the same method as denary, this gives the headings 20, 21, 22, 23, and so on. The typical headings for a binary number with eight digits would be: (27) (26) (25) (24) (23) (22) (21) (20) 128 64 32 16 8 4 2 1 1 1 1 0 1 1 1 0 A typical binary number would be: 11101110. Converting from binary to denary The conversion from binary to denary is a relatively straightforward process. Each time a 1-value appears in a binary number column, the column value (heading) is added to a total. This is best shown by three examples which use 8-bit, 12-bit and 16-bit binary numbers: Example 1 Convert the binary number, 11101110, into a denary number. 128 64 32 16 8 4 2 1 1 1 1 0 1 1 1 0 The equivalent denary number is 128 + 64 + 32 + 8 + 4 + 2 = 238 Example 2 Convert the following binary number, 011110001011, into a denary number. 2048 1024 512 256 128 64 32 16 8 4 2 1 0 1 1 1 1 0 0 0 1 0 1 1 The equivalent denary number is 1024 + 512 + 256 + 128 + 8 + 2 + 1 = 1931 3 318281_C01_CAM_IGCSE CO_SCI_001_044.indd 3 18/02/21 3:22 PM 1 Data representation Example 3 Convert the following binary number, 0011000111100110, into a denary number. 32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1 0 0 1 1 0 0 0 1 1 1 1 0 0 1 1 0 As with the two examples above, to convert this number to denary, each time a 1 appears in a column the column value is added to the total: 8192 + 4096 + 256 + 128 + 64 + 32 + 4 + 2 = 12 774 The same method can be used for a binary number of any size. Activity 1.1 Convert the following binary numbers into denary: a 0 0 1 1 0 0 1 1 k 0001 1110 0111 b 0 1 1 1 1 1 1 1 l 0101 0101 0100 c 1 0 0 1 1 0 0 1 m 1111 0000 1111 d 0 1 1 1 0 1 0 0 n 0111 1100 1000 e 1 1 1 1 1 1 1 1 o 0111 1111 1111 f 0 0 0 0 1 1 1 1 p 0111 1100 1111 0000 g 1 0 0 0 1 1 1 1 q 0011 1111 0000 1101 h 1 0 1 1 0 0 1 1 r 1100 0011 0011 1111 i 0 1 1 1 0 0 0 0 s 1000 1000 1000 1000 j 1 1 1 0 1 1 1 0 t 0111 1111 1111 1111 Converting from denary to binary The conversion from denary numbers to binary numbers can be done in two different ways. The first method involves successive subtraction of powers of 2 (that is, 128, 64, 32, 16, and so on); whilst the second method involves successive division by 2 until the value “0” is reached. This is best shown by two examples: Example 1 Consider the conversion of the denary number, 142, into binary: Method 1 The denary number 142 is made up of 128 + 8 + 4 + 2 (that is, 142 – 128 = 14; 14 – 8 = 6; 6 – 4 = 2; 2 – 2 = 0; in each stage, subtract the largest possible power of 2 and keep doing this until the value 0 is reached. This will give us the following 8-bit binary number: 128 64 32 16 8 4 2 1 1 0 0 0 1 1 1 0 4 318281_C01_CAM_IGCSE CO_SCI_001_044.indd 4 18/02/21 3:22 PM 1.1 Number systems Method 2 This method involves successive division by 2. Start with the denary number, 142, and divide it by 2. Write the result of the division including the remainder (even if it is 0) under the 142 (that is, 142 ÷ 2 = 71 remainder 0); then divide again by 2 (that is, 71 ÷ 2 = 35 remainder 1) and keep dividing until the result is zero. Finally write down all the remainders in reverse order: 2 142 read the remainders from bottom to top to get the binary number: 2 71 remainder: 0 1 0 0 0 1 1 1 0 2 35 remainder: 1 2 17 remainder: 1 2 8 remainder: 1 2 4 remainder: 0 2 2 remainder: 0 2 1 remainder: 0 0 remainder: 1 ▲ Figure 1.1 We end up with an 8-bit binary number which is the same as that found by Method 1. Example 2 Consider the conversion of the denary number, 59, into binary: Method 1 The denary number 59 is made up of 32 + 16 + 8 + 2 + 1 (that is, 59 – 32 = 27; 27 – 16 = 11; 11 – 8 = 3; 3 – 2 = 1; 1 – 1 = 0; in each stage, subtract the largest possible power of 2 and keep doing this until the value 0 is reached. This will give us the following 8-bit binary number: 128 64 32 16 8 4 2 1 0 0 1 1 1 0 1 1 Method 2 This method involves successive division by 2. Start with the denary number, 59, and divide it by 2. Write the result of the division including the remainder (even if it is 0) under the 59 (that is, 59 ÷ 2 = 29 remainder 1); then divide again by 2 (that is, 29 ÷ 2 = 14 remainder 1) and keep dividing until the result is zero. Finally write down all the remainders in reverse order: 2 59 write the remainders from bottom to top to get the binary number: 2 29 remainder: 1 2 14 remainder: 1 1 1 1 0 1 1 2 7 remainder: 0 2 3 remainder: 1 2 1 remainder: 1 0 remainder: 1 ▲ Figure 1.1b 5 318281_C01_CAM_IGCSE CO_SCI_001_044.indd 5 18/02/21 3:22 PM 1 Data representation If we want to show this as an 8-bit binary number (as shown in Method 1), we now simply add two 0’s from the left-hand side to give the result: 0 0 1 1 1 0 1 1. The two results from both methods clearly agree. Both the above examples use 8-bit binary numbers. This third example shows how the method can still be used for any size of binary number; in this case a 16-bit binary number. Example 3 Consider the conversion of the denary number, 35 000, into a 16-bit binary number: Method 1 The denary number 35 000 is made up of 32 768 + 2048 + 128 + 32 + 16 + 8 (that is, 35 000 – 32 768 = 2232; 2232 – 2048 = 184; 184 – 128 = 56; 56 – 32 = 24; 24 – 16 = 8; 8 – 8 = 0; in each stage, subtract the largest possible power of 2 and keep doing this until the value 0 is reached. This will give us the following 16-bit binary number: 32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1 1 0 0 0 1 0 0 0 1 0 1 1 1 0 0 0 Method 2 This method involves successive division by 2. Start with the denary number, 35000, and divide it by 2. Write the result of the division including the remainder (even if it is 0) under the 35 000 (that is, 35 000 ÷ 2 = 17 500 remainder 0); then divide again by 2 (that is, 17 500 ÷ 2 = 8750 remainder 0) and keep dividing until the result is zero. Finally write down all the remainders in reverse order: 2 35 000 read the remainder from bottom to top to get the binary number: 2 17 500 remainder: 0 2 8750 remainder: 0 1 0 0 0 1 0 0 0 1 0 1 1 1 0 0 0 2 4375 remainder: 0 2 2187 remainder: 1 2 1093 remainder: 1 2 546 remainder: 1 2 273 remainder: 0 2 136 remainder: 1 2 68 remainder 0 2 34 remainder 0 2 17 remainder 0 2 8 remainder 1 2 4 remainder 0 2 2 remainder 0 2 1 remainder 0 0 remainder 1 ▲ Figure 1.1c 6 318281_C01_CAM_IGCSE CO_SCI_001_044.indd 6 25/02/21 11:12 AM 1.1 Number systems Activity 1.2 Convert the following denary numbers into binary (using both methods): a 41 d 100 g 144 j 255 m 4095 b 67 e 111 h 189 k 33000 n 16400 c 86 f 127 i 200 l 888 o 62307 The hexadecimal system The hexadecimal number system is very closely related to the binary system. Hexadecimal (sometimes referred to as simply ‘hex’) is a base 16 system and therefore needs to use 16 different ‘digits’ to represent each value. Because it is a system based on 16 different digits, the numbers 0 to 9 and the letters A to F are used to represent each hexadecimal (hex) digit. A in hex = 10 in denary, B = 11, C = 12, D = 13, E = 14 and F = 15. Using the same method as for denary and binary, this gives the headings 160, 161, 162, 163, and so on. The typical headings for a hexadecimal number with five digits would be: (164) (163) (162) (161) (160) 65 536 4096 256 16 1 2 1 F 3 A A typical example of hex is 2 1 F 3 A. Since 16 = 24 this means that FOUR binary digits are equivalent to each hexadecimal digit. The following table summarises the link between binary, hexadecimal and denary: ▼ Table 1.1 Binary value Hexadecimal value Denary value 0000 0 0 0001 1 1 0010 2 2 0011 3 3 0100 4 4 0101 5 5 0110 6 6 0111 7 7 1000 8 8 1001 9 9 1010 A 10 1011 B 11 1100 C 12 1101 D 13 1110 E 14 1111 F 15 7 318281_C01_CAM_IGCSE CO_SCI_001_044.indd 7 18/02/21 3:22 PM 1 Data representation Converting from binary to hexadecimal and from hexadecimal to binary Converting 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 0s from the left. Take each group of 4 bits and convert it into the equivalent hexadecimal digit using Table 1.1. Look at the following two examples to see how this works. Example 1 101111100001 First split this up into groups of 4 bits: 1011 1110 0001 Then, using Table 1.1, find the equivalent hexadecimal digits: B E 1 Example 2 10000111111101 First split this up into groups of 4 bits: 10 0001 1111 1101 The left group only contains 2 bits, so add in two 0s: 0010 0001 1111 1101 Now use Table 1.1 to find the equivalent hexadecimal digits:    2 1 F D 8 318281_C01_CAM_IGCSE CO_SCI_001_044.indd 8 18/02/21 3:22 PM 1.1 Number systems Activity 1.3 Convert the following binary numbers into hexadecimal: a 1 1 0 0 0 0 1 1 b 1 1 1 1 0 1 1 1 c 1 0 0 1 1 1 1 1 1 1 d 1 0 0 1 1 1 0 1 1 1 0 e 0 0 0 1 1 1 1 0 0 0 0 1 f 1 0 0 0 1 0 0 1 1 1 1 0 g 0 0 1 0 0 1 1 1 1 1 1 1 0 h 0 1 1 1 0 1 0 0 1 1 1 0 0 i 1 1 1 1 1 1 1 1 0 1 1 1 1 1 0 1 j 0 0 1 1 0 0 1 1 1 1 0 1 0 1 1 1 0 Converting from hexadecimal to binary is also very straightforward. Using the data in Table 1.1, simply take each hexadecimal digit and write down the 4-bit code which corresponds to the digit. Example 3 4 5 A Using Table 1.1, find the 4 bit code for each digit: 0 1 0 0 0 1 0 1 1 0 1 0 Put the groups together to form the binary number: 0 1 0 0 0 1 0 1 1 0 1 0 Example 4 B F 0 8 Again just use Table 1.1: 1 0 1 1 1 1 1 1 0 0 0 0 1 0 0 0 Then put all the digits together: 1 0 1 1 1 1 1 1 0 0 0 0 1 0 0 0 9 318281_C01_CAM_IGCSE CO_SCI_001_044.indd 9 18/02/21 3:22 PM 1 Data representation Activity 1.4 Convert the following hexadecimal numbers into binary: a 6 C f B A 6 b 5 9 g 9 C C c A A h 4 0 A A d A 0 0 i D A 4 7 e 4 0 E j 1 A B 0 Converting from hexadecimal to denary and from denary to hexadecimal To convert hexadecimal numbers into denary involves the value headings of each hexadecimal digit; that is, 4096, 256, 16 and 1. Take each of the hexadecimal digits and multiply it by the heading values. Add all the resultant totals together to give the denary number. Remember that the hex digits A → F need to be first converted to the values 10 → 15 before carrying out the multiplication. This is best shown by two examples: Example 1 Convert the hexadecimal number, 4 5 A, into denary. First of all we have to multiply each hex digit by its heading value: 256 16 1 4 5 A (4 × 256 = 1024) (5 × 16 = 80) (10 × 1 = 10) (NOTE: A = 10) Then we have to add the three totals together (1024 + 80 + 10) to give the denary number: 1 1 1 4 Example 2 Convert the hexadecimal number, C 8 F, into denary. First of all we have to multiply each hex digit by its heading value: 256 16 1 C 8 F (12 × 256 = 3072) (8 × 16 = 128) (15 × 1 = 15) (NOTE: C = 12, F = 15) Then we have to add the three totals together (3072 + 128 + 15) to give the denary number: 3 2 1 5 10 318281_C01_CAM_IGCSE CO_SCI_001_044.indd 10 18/02/21 3:22 PM 1.1 Number systems Activity 1.5 Convert the following hexadecimal numbers into denary: a 6 B f A 0 1 b 9 C g B B 4 c 4 A h C A 8 d F F i 1 2 A E e 1 F F j A D 8 9 To convert from denary to hexadecimal involves successive division by 16 until the value “0” is reached. This is best shown by two examples: Example 1 Convert the denary number, 2004, into hexadecimal. This method involves successive division by 16 until the value 0 is reached. We start by dividing the number 2004 by 16. The result of the division including the remainder (even if it is 0) is written under 2004 and then further divisions by 16 are carried out (that is, 2004 ÷ 16 = 125 remainder 4; 125 ÷ 16 = 7 remainder 13; 7 ÷ 16 = 0 remainder 7). The hexadecimal number is obtained from the remainders written in reverse order: 16 2004 write the remainders from bottom to top to get the hexadecimal number: 16 125 remainder: 4 16 7 remainder: 13 7 D 4 (D=13) 0 remainder: 7 ▲ Figure 1.2a Example 2 Convert the denary number, 8463, into hexadecimal. We start by dividing the number 8463 by 16. The result of the division including the remainder (even if it is 0) is written under 8463 and then further divisions by 16 are carried out (that is, 8463 ÷ 16 = 528 remainder 15; 528 ÷ 16 = 33 remainder 0; 33 ÷ 16 = 2 remainder 1; 2 ÷ 16 = 0 remainder 2). The hexadecimal number is obtained from the remainders written in reverse order: 16 8463 read the remainder from bottom to top to get the hexadecimal number: 16 528 remainder: 15 2 1 0 F (F=15) 16 33 remainder: 0 16 2 remainder: 1 0 remainder: 2 ▲ Figure 1.2b 11 318281_C01_CAM_IGCSE CO_SCI_001_044.indd 11 18/02/21 3:22 PM 1 Data representation Activity 1.6 Convert the following denary numbers into hexadecimal: a 9 8 f 1 0 0 0 b 2 2 7 g 2 6 3 4 c 4 9 0 h 3 7 4 3 d 5 1 1 i 4 0 0 7 e 8 2 6 j 5 0 0 0 1.1.3 Use of the hexadecimal system As we have seen, a computer can only work with binary data. Whilst computer scientists can work with binary, they find hexadecimal to be more convenient to use. This is because one hex digit represents four binary digits. A complex binary number, such as 1101001010101111 can be written in hex as D2AF. The hex number is far easier for humans to remember, copy and work with. This section reviews four uses of the hexadecimal system: » error codes » MAC addresses » IPv6 addresses » HTML colour codes The information in this section gives the reader sufficient grounding in each topic at this level. Further material can be found by searching the internet, but be careful that you don’t go off at a tangent. Error codes Error codes are often shown as hexadecimal values. These numbers refer to the memory location of the error and are usually automatically generated by the computer. The programmer needs to know how to interpret the hexadecimal error codes. Examples of error codes from a Windows system are shown below: Find out more Another method used to trace errors during program development is to use memory dumps, where the memory contents are printed out either on screen or using a printer. Find examples of memory dumps and find out why these are a very useful tool for program developers. ▲ Figure 1.3 Example of error codes 12 318281_C01_CAM_IGCSE CO_SCI_001_044.indd 12 18/02/21 3:22 PM 1.1 Number systems Media Access Control (MAC) addresses Media Access Control (MAC) address refers to a number which uniquely identifies a device on a network. The MAC address refers to the network interface card (NIC) which is part of the device. The MAC 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 6 groups of two hexadecimal digits (although 64-bit addresses also exist): NN – NN – NN – DD – DD – DD or 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 – DD – DD) is the serial number of the device. For example: 00 – 1C – B3 – 4F – 25 – FE is the MAC address of a device produced by the Apple Corporation (code: 001CB3) with a serial number of: 4F25FE. Very often lowercase Link hexadecimal letters are used in the MAC address: 00-1c-b3-4f-25-fe. Other manufacturer identification numbers include: Refer to Chapter 3 for more detail on MAC 00 – 14 – 22 which identifies devices made by Dell addresses. 00 – 40 – 96 which identifies devices made by Cisco Find out more Try to find the MAC 00 – a0 – c9 which identifies devices made by Intel, and so on. addresses of some of your own devices (e.g. mobile phone and Internet Protocol (IP) addresses tablet) and those found Each device connected to a network is given an address known as the Internet in the school. Protocol (IP) address. An IPv4 address is a 32-bit number written in denary or hexadecimal form: e.g. 109.108.158.1 (or 77.76.9e.01 in hex). IPv4 has recently been improved upon by the adoption of IPv6. An IPv6 address is a 128-bit Link number broken down into 16-bit chunks, represented by a hexadecimal number. For example: Refer to Chapter 3 for more detail on IP a8fb:7a88:fff0:0fff:3d21:2085:66fb:f0fa addresses. Note IPv6 uses a colon (:) rather than a decimal point (.) as used in IPv4. Find out more HyperText Mark-up Language (HTML) colour codes HyperText Mark-up Language (HTML) is used when writing and developing web Try to find the IPv4 pages. HTML isn’t a programming language but is simply a mark-up language. A and IPv6 addresses of some of your own mark-up language is used in the processing, definition and presentation of text devices (e.g. mobile (for example, specifying the colour of the text). phone and tablet) and HTML uses which are used to bracket a piece of text for example, those found in the school. and surround a top-level heading. Whatever is between the two tags has been defined as heading level 1. Here is a short example of HTML code: 13 318281_C01_CAM_IGCSE CO_SCI_001_044.indd 13 18/02/21 3:22 PM 1 Data representation This is a red heading This is a green heading This is a blue heading ▲ Figure 1.4 HTML is often used to represent colours of text on the computer screen. All colours can be made up of different combinations of the three primary colours (red, green and blue). The different intensity of each colour (red, green and blue) is determined by its hexadecimal value. This means different hexadecimal values represent different colours. 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 fuchsia » # FF 80 00 represents orange » # B1 89 04 represents a tan colour, and so on producing almost any colour the user wants. The following diagrams show the various colours that can be selected by altering the hex ‘intensity’ of red, green and blue primary colours. The colour ‘FF9966’ has been chosen as an example: FF 99 66 ▲ Figure 1.5 Examples of HTML hex colour codes The # symbol always precedes hexadecimal values in HTML code. The colour codes are always six hexadecimal digits representing the red, green and blue components. There are a possible 256 values for red, 256 values for green and 256 values for blue giving a total of 256 × 256 × 256 (i.e. 16 777 216) possible colours. 14 318281_C01_CAM_IGCSE CO_SCI_001_044.indd 14 18/02/21 3:22 PM 1.1 Number systems Activity 1.7 1 Using software on your computer (for example, text colour option in Word), find out what colours would be represented by the following RGB denary value combinations: a Red 53 b Red 201 c Red 12 Green 55 Green 122 Green 111 Blue 139 Blue 204 Blue 81 2 Convert each of the above denary numbers into hexadecimal. 1.1.4 Addition of binary numbers This section will look at the addition of two 8-bit positive binary numbers. Note the following key facts when carrying out addition of two binary digits: binary addition carry sum 0+0 0 0 0+1 0 1 1+0 0 1 1+1 1 0 This can then be extended to consider the addition of three binary digits: binary digit carry sum 0+0+0 0 0 0+0+1 0 1 0+1+0 0 1 0+1+1 1 0 For comparison: if we add 7 and 9 1+0+0 0 1 in denary the result is: carry = 1 1+0+1 1 0 and sum = 6; if we add 7, 9 and 1+1+0 1 0 8 the result is: carry = 2 and sum 1+1+1 1 1 = 4, and so on. Advice Here’s a quick recap on the role of carry and sum. If we want to add the numbers 97 and 64 in decimal, we: l add the numbers in the right hand column first l if the sum is greater than 9 then we carry a value to the next column l we continue moving left, adding any carry values to each column until we are finished. For instance: 9 7 + 64 1 1 CARRY VALUES 1 6 1 SUM VALUES Adding in binary follows the same rules except that we carry whenever the sum is greater than 1. 15 318281_C01_CAM_IGCSE CO_SCI_001_044.indd 15 18/02/21 3:22 PM 1 Data representation Example 1 Add 00100111 + 01001010 We will set this out showing carry and sum values: 00100111 column 1: 1 + 0 = 1 no carry + column 2: 1 + 1 = 0 carry 1 01001010 column 3: 1 + 0 + 1 = 0 carry 1 column 4: 0 + 1 + 1 = 0 carry 1 111 carry values column 5: 0 + 0 + 1 = 1 no carry 01110001 sum values column 6: 1 + 0 = 1 no carry column 7: 0 + 1 = 1 no carry Answer: 01110001 column 8: 0 + 0 = 0 no carry Example 2 a Convert 126 and 62 into binary. b Add the two binary values in part a and check the result matches the addition of the two denary numbers a 126 = 0 1 1 1 1 1 1 0 and 62 = 0 0 1 1 1 1 1 0 column 1: 0 + 0 = 0 no carry b 01111110 column 2: 1 + 1 = 0 carry 1 + column 3: 1 + 1 + 1 = 1 carry 1 00111110 column 4: 1 + 1 + 1 = 1 carry 1 column 5: 1 + 1 + 1 = 1 carry 1 111111 carry values column 6: 1 + 1 + 1 = 1 carry 1 column 7: 1 + 0 + 1 = 0 carry 1 10111100 sum values column 8: 0 + 0 + 1 = 1 no carry Answer: 10111100 1 0 1 1 1 1 0 0 has the equivalent denary value of 128 + 32 + 16 + 8 + 4 = 188 which is the same as 126 + 62. Activity 1.8 Carry out the following binary additions: a 00011101+01100110 f 00111100+01111011 b 00100111+00111111 g 00111111+00111111 c 00101110+01001101 h 00110001+00111111 d 01110111+00111111

Use Quizgecko on...
Browser
Browser