IGCSE Computer Science - Sample

Page 1

FT

Computer Science for Cambridge IGCSEâ„¢ & O Level COURSEBOOK

D

R

A

Sarah Lawrey and Victoria Ellis

Second edition

Digital Access


D

R

A

FT

Introduction: Under the hood of a computer

Original material Š Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


CAMBRIDGE IGCSE™ & O-LEVEL COMPUTER SCIENCE: COURSEBOOK

What is computer science? Computer Science is the study of computers and computational thinking. It includes the purpose and operation of hardware, software and networks. Computer science involves studying theoretical ideas about how data is processed and stored, and what would be necessary to perform such theoretical operations. It is also the practical application of these ideas to create new hardware and software. Studying hardware involves learning about the basic design of computers and how they operate, including how they perform calculations, logical operations and how they store data. It involves understanding how and why binary is used in a computer for these processes.

FT

Studying software involves learning about the different programming concepts and how to apply these in different programming languages. It involves looking at how translators are used to convert programming languages into the necessary binary state needed for a computer to process. It also involves learning about different types of software, such as operating systems and applications.

Hardware and software used by a child

D

R

A

Studying networks involves learning about how data is transmitted across a network, including some of the components involved in this process. It also involves looking at the risks involved in using a network and how you can use different methods to help prevent exposure to these risks.

2 Original material Š Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


Introduction

Why should you study computer science? Over the years since their invention, computers have dramatically changed the way many of us live. The introduction of the personal computer (PC) into many homes around the world has led to the development of the internet, which began to transform the way that many people communicate and share information.

FT

The use of computer systems is now a widespread practice. They range from small embedded systems in our everyday devices, such as refrigerators, traffic lights, digital cameras and washing machines, to being responsible for handling the world’s money in huge banking systems.

Hardware and software used in an industrial setting

There are many aspects of our life today that would not be possible on the same scale without the use of computers, so studying what they are, how they work and the many purposes they have can be both fun and exciting. It can also be very interesting and challenging as you try to understand the complex nature of their operation.

A

There are many lifelong skills that you can develop through learning about computer science, these including logical thinking, creativity and problem solving. These are all skills that add to your employability status in the future.

R

Computer scientists are needed in many different industries, so the choice of career that you could take is very open. Industries such as science, engineering, finance, manufacturing, sports and healthcare all use a wide variety of computers and require lifelong skills that the study of computer science builds.

D

Computers advance on a constant basis, so being part of the study of how that happens keeps your studies relevant and engaging. What are you waiting for? Let the enjoyment begin!

Computers being used in an office environment

Aeronautical engineer using a tablet computer

3 Original material Š Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


CAMBRIDGE IGCSE™ & O-LEVEL COMPUTER SCIENCE: COURSEBOOK

Exercise classes can be accessed via a home computer

FT

Doctors performing robotic surgery

Under the hood of a computer

In order to study their wider purpose, it is useful to understand what exactly is ‘under the hood’ of a computer. Let’s look at a personal computer (PC), what are the components that they contain?

Computer case

R

Computer case fan

RAM

A

Power supply unit

Optical drive

CPU cooling fan

D

Hard drive

CPU (under the fan)

Graphics card

Motherboard

Inside a desktop computer case

4 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


Introduction

Computer case

FT

The computer case is the unit in which all the other components are stored. The case stops too much dust getting to the computer components, which can harm them and affect the way that they are able to perform. The size of a case is often dictated by the size of the motherboard that it will store, as this is one of the larger components within the computer. Computer cases have been made from all kinds of material such as steel, aluminium, plastic, wood, glass and even Lego!

A

A computer case

Computer Case Fan

D

R

The components inside a computer consume power to operate. This means that they can often get quite hot. A computer case has a fan that is attached to the side of it that spins to keep the components within the case nice and cool. If a computer is needed for high performing tasks that will require more power, it can often have more than one case fan.

Computer case fans

5 Original material Š Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


CAMBRIDGE IGCSE™ & O-LEVEL COMPUTER SCIENCE: COURSEBOOK

Motherboard The motherboard is a very important component in a computer. All the other components in the computer plug into the motherboard. The motherboard allows the components to be connected and to communicate in order to carry out all the operations. It also allows all the components to receive the power that comes from the power supply unit. It is a large and very important circuit board. It is often thought of as the backbone of a computer as it holds all the other components together.

The motherboard

D

R

A

FT

The motherboard has a special unit in which the CPU is seated. It also has lots of special slots that components such as the RAM and the graphics card are clipped into. It has lots of pins around the edges where cables can be plugged into to power the different components.

6 Original material Š Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


Introduction

CPU The central processing unit (CPU) is a very important component within a computer. It is known as the brains of the computer. It is responsible for the operation of each fetch-decode-execute cycle that the computer carries out. You will learn a lot more about the CPU and what it does in Chapter 3. You can find it inserted into a special unit on the motherboard. It’s a very small component but has a very big job!

CPU Cooling Fan

FT

The CPU

R

A

One component that can get very hot in a computer is the CPU. It is constantly working and it is completing millions of cycles each second. It is vital that the CPU doesn’t get too hot or it will no longer work. Therefore, the CPU normally has its own fan that sits directly on top of it. This keeps it running at the best temperature for it to operate. CPU cooling fans can just be a simple fan, or they can be as elaborate as very fancy water cooling systems to keep the CPU at the best temperature.

Power Supply Unit

A water cooled CPU

D

All the components in a computer need power to operate. They are all connected to the motherboard to get access to power. There is one component that powers the motherboard to allow it to pass power to the other components and this is called the power supply unit (PSU). PSUs can have different levels of wattage output. The higher the wattage, the more powerful the PSU. A standard computer will need a PSU that outputs approximately 300 to 500 watts. A computer that has lots of high performance components will need a more powerful PSU to supply a higher level of power. A PSU like this could output over 1000 watts.

A power supply unit

7 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


CAMBRIDGE IGCSE™ & O-LEVEL COMPUTER SCIENCE: COURSEBOOK

RAM

Graphics card

FT

The random access memory (RAM) is the component that temporarily stores data in a computer that is waiting to be processed. RAM is plugged into the motherboard and is available in different storage sizes. A common size of RAM for a computer to have is 8 GB of RAM. However, if a computer is a high performance computer, it will have a lot more data that needs to be processed each second, so it will need a larger amount of RAM. A computer like this could have 32 GB of RAM. The amount of RAM RAM memory modules a computer has can be upgraded. RAM is commonly available in sizes of 8 GB. So, another 8 GB card can be inserted into a RAM slot on the motherboard to upgrade the amount of RAM by 8 GBs. You will learn more about the purpose of RAM in Chapter 3.

R

A

A graphics card is the component in the computer that is responsible for producing the images that you see on your computer screen. Some computers have a graphics unit built into the motherboard, this is called a graphics processing unit (GPU). However, most GPUs are low performing and not capable of producing the high quality of graphics seen by most computers today. Therefore, graphics cards are now more commonly used in computers to produce the high quality of graphics desired by many users. The graphics card plugs into a special slot on the motherboard. Like the CPU, a graphics card is responsible for processing a lot of data, so it normally has built in fans to keep it cool and stop it from overheating.

A graphics card

Hard drive

D

The hard drive is where all the files and software that you use on your computer are permanently stored. Most computers will either have a hard disk drive (HDD) or a solid state drive (SSD). It is common in computers now to have approximately 1 TB of storage, but earlier computers only had 250–500 GB of data storage. The demand for an increasing amount of storage space continues as we store more and more data on our computers. Some companies have predicted this demand and have started to encourage users to use cloud storage as a result. You will learn more about the operation of a HDD and an SSD, and you will also learn more about cloud storage in Chapter 3.

A hard drive

8 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


Introduction

Optical drive The final component is an optical drive. This is the device in which you insert optical media such as CDs into, to be read by the computer. Optical drives used to be very common in computers, but more modern computers are often now manufactured without them. This is because a lot of content and data is now digital shared and the need for using CDs to share data has decreased as a result.

An optical drive

D

R

A

FT

You now know what is inside a computer case, eagerly working hard to complete all the actions that you ask of your computer. You now get to learn some exciting information about computer science, including how some of those components work on a more detailed level, and you get to learn how to create the computer programs that are processed by your computer. Let’s get started!

9 Original material Š Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


Chapter 1

R

A

FT

Data representation

D

IN THIS CHAPTER YOU WILL: •

learn why computers use binary to process data

develop an understanding about how binary is used to represent different forms of data, such as text, sound and images

learn to convert between the number systems denary, binary and hexadecimal

learn to add two binary numbers and understand what is meant by overflow

learn to perform a binary shift and how this affects the number

learn to use two’s compliment to represent negative binary numbers

learn how the file size of data is measured

learn how and why data is compressed.

Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


1  Data representation

GETTING STARTED Working with a partner, write the words ‘text’, ‘sound’ and ‘image’ on a piece of paper. Around each word, write words that you can think of that are linked to each of the three words. Here is an example to get you started; you could write the words ‘sound wave’ next to the word ‘sound’.

DEBUGGING USING HEXADECIMAL

KEY WORD

FT

Computer programs are the foundation of computer games. If there is an error with the program, this can cause unexpected behaviour in the game. For example, a character may move the wrong way when a button is pressed. The programmer needs to find out why the character is moving incorrectly. The amount of code that needs to be assessed to find this error in a computer game is enormous and the binary values involved will be vast. Therefore, the programmer will often use hexadecimal to debug the error. One way this can be done is to look at the address for a variable. The address is the location in memory where the data is stored and it is shown in hexadecimal. This address is then looked up in a table to find the value held in the address. The value is also given as hexadecimal. If the value in the address is, for example, 0000 or FFFF (this can mean that the variable has not been initiated) the programmer will know that there is a problem with this value and has located the variable with which the error is occurring. The programmer can then find out why the variable is not holding a valid value.

A

hexadecimal: a base-16 number system that uses the values 0–9 and characters A–F.

D

R

If the addresses and values were given as binary, rather than as hexadecimal, then it would be more difficult to identify if an error has occurred. For example, it is easier to see if an address contains a valid value, e.g. F2A5, rather than 1111001010100101.

Figure 1.1: Data represented by hexadecimal letters and numbers

11 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


CAMBRIDGE IGCSE™ & O-LEVEL COMPUTER SCIENCE: COURSEBOOK

CONTINUED Discussion questions 1

Do you think that you have ever seen used hexadecimal before? If you have, can you provide an example of where you have seen or used it?

2

Why is it important for a programmer to be able to effectively debug a computer program?

1.1 Binary and hexadecimal

FT

Humans process a large amount of data on a daily basis. Did you know that when we have a conversation with someone, we process approximately 60 bits of information per second? Our brain is designed to process a maximum of about 120 bits per second. That’s why it is so difficult to listen to two people talk to us at once! As humans, we process data that is called analogue data. Everything we see, hear, feel and smell is a continuous stream of analogue data to our senses.

Questions

Can you think of three examples of analogue data? Why is analogue data described as continuous data?

A

1 2

R

The components that process data in a computer are made up of very small logic gates. These gates cannot process analogue data, they can only process digital data. This data is stored in registers. You can find out more about logic gates in Chapter 10. Digital data is discreet data that only has two values, 1 and 0. Any data that we want a computer to process must be converted into digital data. This type of data is also called binary data.

Number systems

D

In our daily lives we mostly use a denary number system. This is called a base-10 number system and uses the digits 0–9. The units in a denary number system are ones, tens, hundreds and thousands. Each time the unit increases by the power of 10. For example, the denary number 123 has: Increases by power of 10

Increases by power of 10

One hundred

Two tens

Three ones

1

2

3

KEY WORDS analogue data: a continuous stream of data that is processed by humans. logic gate: a very small component in a computer system that controls the flow of electricity. digital data: discreet data that only uses the values 0 and 1. register: a small component in a computer system that is used to temporarily store data. binary: a base-2 number system that uses the values 0 and 1. denary: a base-10 number system that uses the values 0–9.

Computers use a binary number system. This is called a base-2 number system and uses the digits 0 and 1. The units in a binary number system increase by the power of 2. Any denary values need to be converted to binary values so that they can be processed by a computer.

12 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


1  Data representation

SKILLS FOCUS 1.1 CONVERTING BETWEEN DENARY AND BINARY NUMBERS The size of a binary number is referred to by the number of bits it has. A 4-bit binary number will have 4 values that are either 1 or 0, for example, 1001. An 8-bit binary number will have 8 values that are also either 1 or 0. Binary values can get very large, some have as many as 64 bits; now that’s a very big number! You need to be able to understand binary numbers that have as many as 16 bits. First, focus on converting denary numbers to 4-bit binary. To convert denary numbers to 4-bit binary the units that you need to use are 1, 2, 4 and 8. You can indicate with a 1 or a 0 whether that unit is required. For example, if you convert the denary number 13 to a 4-bit binary number you can use the following steps:

8

FT

Write down the binary units from 8 to 1. An easy way to do this is using a table. 4

2

1

Do you notice how the units increase by the power of 2 each time (going from right to left)?

Compare the denary number (13) to the first binary unit (8) to see whether it is equal to or greater than the denary number. 13 is greater than 8, which means that the unit 8 is required and you can write a 1 beneath it. 8 can then be subtracted from the denary value, 13 – 8 = 5. 4

1

2

1

A

8

8 1

R

Now compare the denary number (5) to the next binary unit (4) to see whether it is equal to or greater than the denary number. 5 is greater than 4, which means that the unit 4 is required and you can write a 1 beneath it. 4 can then be subtracted from the denary value, 5 – 4 = 1. 4

2

1

1

D

Then compare the denary number (1) to the next binary unit (2) to see whether it is equal to or greater than the denary number. 1 is not greater than 2, which means that the unit 2 is not required and you can write a 0 beneath it. No subtraction is needed this time as you haven’t used the unit. 8

4

2

1

1

0

1

Finally, compare the denary number (1) to the last binary unit (1) to see whether it is equal to or greater than the denary number. 1 is equal to 1, which means that the unit is required and you can write a 1 beneath it. 1 can then be subtracted from the denary value. 1 − 1 = 0. 8

4

2

1

1

1

0

1

13 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


CAMBRIDGE IGCSE™ & O-LEVEL COMPUTER SCIENCE: COURSEBOOK

CONTINUED This means that if you convert the denary number 13 to 4-bit binary, you get the binary number 1101. Questions 1 2 3

What is the largest denary number that can be created with a 4-bit binary number? Convert the denary number 6 to a 4-bit binary number. Convert the binary number 9 to a 4-bit binary number.

FT

To convert denary numbers to 8-bit binary the units that you need to use are 1, 2, 4, 8, 16, 32, 64 and 128. You can indicate, again, with a 1 or a 0 whether that unit is required. For example, if you convert the denary number 150 to an 8-bit binary number you can use the same method as before: Write down the binary units from 128 to 1: 128

64

32

16

8

4

2

1

128

64

1

A

Compare the denary number (150) to the first binary unit (128) to see whether it is equal to or greater than the denary number. 150 is greater than 128, which means that the unit 128 is required and you can write a 1 beneath it. 128 can then be subtracted from the denary value, 128 – 150 = 22. 32

16

8

4

2

1

128 1

R

Next, compare the denary number (22) to the next binary unit (64) to see whether it is equal to or greater than the denary number. 22 is not greater than 64, which means that the unit 64 is not required and you can write a 0 beneath it. No subtraction is needed this time as you haven’t used the unit. 64

32

16

8

4

2

1

0

D

Then compare the denary number (22) to the next binary unit (32) to see whether it is equal to or greater than the denary number. 22 is not greater than 32, which means that the unit 32 is not required and you can write a 0 beneath it. No subtraction is needed this time as you haven’t used the unit. 128

64

32

1

0

0

16

8

4

2

1

Now, continue this process until you have compared all the binary units. Remember to subtract the unit from the denary number if it is required. You should end with the following result: 128

64

32

16

8

4

2

1

1

0

0

1

0

1

1

0

14 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


1  Data representation

CONTINUED This means that if you convert the denary number 150 to 8-bit binary, you get the binary number 10010110. A quick check that you can do on your calculation is to look at the last unit on the right of your binary number. If the denary number you are converting is an odd number, this number should be 1. If the denary number you are converting is an even number, this number should be 0. Questions 4 5

Convert the denary number 58 to an 8-bit binary number. Convert the denary number 123 to an 8-bit binary number.

FT

If you need to convert a binary number into a denary number, you can use simple addition. You just need to add together all the units that are represented by the value 1. Try converting the binary number 1010. A simple way to do this is to use a table. You can write the units above and the binary number below: 8

4

1

0

2

1

1

0

A

You just need to add together all the units that have a 1 below. This means the calculation is 8 + 2 = 10. Therefore, if you are converting the binary number 1010 to denary, you get the denary number 10. If you need to convert an 8-bit binary number, you need to extend the units so that you have 8 of them. Remember to increase by the power of 2 each time.

128 1

R

Try converting the binary number 10011001. You can write the values in a table again to make it clearer: 64

32

16

8

4

2

1

0

0

1

1

0

0

1

REFLECTION

D

You just need to add together all the units again that have a 1 below. This means the calculation is 128 + 16 + 8 + 1 = 153. Therefore, if you are converting the binary number 100011001 to denary, you get the denary number 153. Questions 6 7 8

0

What is the largest denary number that can be created with an 8-bit binary number? Convert the 8-bit binary number 01100011 to a denary number. You need to be able to convert up to 16-bit binary values. Fill in the missing units in the table and calculate the denary number for the given binary number. 1

1

0

0

0

1

256 128 64

32

16

8

4

2

1

0

0

0

1

0

0

1

1

0

After completing Skills Focus 1.1, it can be helpful to think about how you approached it and ways you improve your research skills for future activities. How did you know how to add in the correct missing units for Question 8? How did you work out each unit?

15 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


CAMBRIDGE IGCSE™ & O-LEVEL COMPUTER SCIENCE: COURSEBOOK

Hexadecimal Hexadecimal is also a number system. Humans can use hexadecimal, but computers cannot process it. Like denary numbers, hexadecimal numbers also need to be converted to binary to be processed by a computer. Hexadecimal is a base-16 system and uses 16 symbols, these are the numbers 0–9 and the letters A–F. This is to allow the denary values 0–15 to be represented in hexadecimal. This is shown in Table 1.1. Denary

0

1

2

3

4

5

6

7

8

9

10 11 12 13 14 15

Hexadecimal

0

1

2

3

4

5

6

7

8

9

A

B

C

D

E

F

Table 1.1: Hexadecimal representations of denary numbers

FT

The reason for using the symbols A–F for the denary numbers 10–15 is so only one symbol is needed for the denary number in hexadecimal.

SKILLS FOCUS 1.2

CONVERTING BETWEEN DENARY NUMBERS AND HEXADECIMAL

To convert a denary number to hexadecimal, it is easier to convert it to binary first. For example:

A

First convert the denary number 7 to 4-bit binary. 8

4

2

1

0

1

1

1

R

To convert the binary number to hexadecimal you can use simple addition again. 4 + 2 + 1 = 7. If you look at the symbol table (Table 1.1), you can see that the hexadecimal for 7 is also 7. Therefore, the denary number 7 is 0111 as binary and 7 as hexadecimal. So, what happens with denary numbers that are greater than 9?

D

First convert the denary number 12 to 4-bit binary. 8

4

2

1

1

1

0

0

To convert the binary number to hexadecimal you can use simple addition again. 8 + 4 = 12. If you look at the symbol table (Table 1.1), you can see that the hexadecimal for 12 is C. Therefore, the denary number 12 is 1100 as binary and 12 as hexadecimal. Converting the denary number to binary first isn’t necessary for denary numbers that are less than 16, but it makes the process easier when you need to convert larger denary numbers. So, how do you convert a larger denary number to hexadecimal?

16 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


1  Data representation

CONTINUED First, convert the denary number 201 to 8-bit binary. You know you can use 8-bit binary because the denary number is less than 256. 128

64

32

16

8

4

2

1

1

1

0

0

1

0

0

1

Each hexadecimal symbol only uses 4 bits. Therefore, you need to split the 8-bit binary number into two 4-bit binary numbers. 8

4

2

1

8

4

2

1

1

1

0

0

1

0

0

1

FT

You then convert each 4-bit binary number again using simple addition. 8 + 4 = 12 8 + 1 = 9

The hexadecimal for 12 is C and the hexadecimal for 9 is 9. Therefore, the denary number 201 converted to binary is 11001001 and to hexadecimal is C9.

To convert a hexadecimal number to a binary number of a denary number you can just reverse the process.

8

4

0

1

A

To convert the hexadecimal number 5E to a binary number you need to convert each symbol to 4-bit binary. Remember E is the number 14. 2 0

8

4

1

1

1

2

1

1

0

E

R

5

1

Therefore, the hexadecimal 5E converted to a binary number is 01011110. To convert the hexadecimal 5E to denary, you can use the binary number that you have just calculated. 64

32

16

D

128 0

1

0

1

8

4

2

1

1

1

1

0

You can add all the units together to get the denary value. 64 + 16 + 8 + 4 + 2 =v94. The hexadecimal 5E converted to a denary number is 94. Questions 1 2 3 4

Convert the hexadecimal A2 to a binary number. Convert the binary number 100111010001 to hexadecimal. Convert the denary number 350 to hexadecimal. Convert the hexadecimal 3AC to a denary number.

17 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


CAMBRIDGE IGCSE™ & O-LEVEL COMPUTER SCIENCE: COURSEBOOK

Why is hexadecimal used in computer science? Programmers often use hexadecimal when writing and analysing computer programs. They do this because it is easy for a human to read hexadecimal, rather than binary. For example, if a programmer looked at a set of data that is stored in registers, as binary it could look like this: 10011100101110111000111011100010111101011010 The programmer may be trying to find out if the data stored matches the correct data which should be: 10011100101110111001011011100010111101011010

FT

At a glance, it is difficult to see whether the two values match or if an error has occurred. If that stored data is represented in hexadecimal it would be: 9CBB8EE2F5A

Comparing it to the correct value that should be: 9CBB96E2F5A

It is much easier to see that the data does not match, and the programmer can identify that an error has occurred. The benefits of using hexadecimal rather than binary for a programmer are:

Hexadecimal is a shorter way of representing binary, so it takes up less space on the computer screen or piece of paper.

Hexadecimal is easier for a programmer to read, write and understand.

Hexadecimal is easier to debug and locate errors in data.

R

ACTIVITY 1.1

A

Each computer has a MAC address. This MAC address is written in hexadecimal. This is one of the ways that hexadecimal is used in computer science.

D

Use the internet to find three more uses of hexadecimal in computer science.

KEY WORDS MAC address: a unique address that is given to a computer at the manufacturing stage that can be used to identify the computer.

1.2 Binary manipulation and negative numbers Binary addition You need to be able to add together two 8-bit binary numbers. When binary numbers are added together there are four rules that you will need to use: Rule 1 is 0 + 0 = 0

18 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


1  Data representation

Rule 2 is 1 + 0 = 1 Rule 3 is 1 + 1 = 10 (this is because 10 in binary is 2) Rule 4 is 1 + 1 + 1 = 11 (this is because 11 in binary is 3) You can apply these rules to add the binary numbers 10010100 and 00011110. +

1

0

0

1

0

1

0

0

0

0

0

1

1

1

1

0

You need to start at the right and begin applying the rules. The first calculation is 0 + 0. Rule The next calculation is 0 + 1. Rule 2 means the result is 1. 1

0

0

1

0

0

0

1

0

1

0

0

FT

+

1

1

1

0

1

0

The next calculation is 1 + 1. Rule 3 means the result is 10. You need to write the 0 in the answer section and carry the 1 to the next calculation. 1

1

0

0

1

0

0

0

1

0

1

0

0

1

1

1

0

0

1

0

A

+

The next calculation is 1 + 0 + 1, which results in 1 + 1. Rule 3 means the result is 10. Write the 0 in the answer section again and carry the 1.

1

0

0

1

1

0

1

0

0

1

1

1

0

0

0

1

0

R

+

1

0

0

0

1

The next calculation is 1 + 1 + 1. Rule 4 means the result is 11. Write 1 in the answer section and carry 1. 1

1

D

1

+

1

0

0

1

0

1

0

0

0

0

0

1

1

1

1

0

1

0

0

1

0

The next calculation is 1 + 0 + 0, which results in 1 + 0. Rule 2 means the result is 1. Write 1 in the answer section. There is no carry this time.

+

1

1

1

1

0

0

1

0

1

0

0

0

0

0

1

1

1

1

0

1

1

0

0

1

0

19 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


CAMBRIDGE IGCSE™ & O-LEVEL COMPUTER SCIENCE: COURSEBOOK

The next calculation is 0 + 0. Rule 1 means the result is 0. Write 0 in the answer section.

+

1

1

1

1

0

0

1

0

1

0

0

0

0

0

1

1

1

1

0

0

1

1

0

0

1

0

The final calculation is 1 + 0. Rules 2 means the result is 1. Write 1 in the answer section.

+

1

1

1

1

0

0

1

0

1

0

0

0

0

0

1

1

1

1

0

1

0

1

1

0

0

1

0

FT

Therefore, when the binary numbers 10010100 and 00011110 are added, the answer is 10110010.

Questions 3 4

Add the 8-bit binary values 00011001 and 01000011. Add the 8-bit binary values 00100110 and 01010111.

A

You should now know that the largest number that can be stored in an 8-bit binary register is 255. What happens when two 8-bit binary values are added, and the result is larger than 255? The following example, almost complete, is very much like the previous calculation with a slightly different binary number. Can you spot the difference?

+

1

1

R

1

1

0

0

1

0

1

0

0

1

0

0

1

1

1

1

0

0

1

1

0

0

1

0

D

If you now try and do the final calculation, that would be 1 + 1 = 10. You write 0 in the answer section, but there is nowhere to carry the 1. This is because the two 8-binary binary values are added the result is 306, which is greater than 255. Therefore, the number cannot fit in the 8-bit register and an overflow error is created.

+

1

1

1

1

1

0

0

1

0

1

0

0

1

0

0

1

1

1

1

0

0

0

1

1

0

0

1

0

KEY WORDS overflow error: a type of error that occurs when a number larger than a register can store is generated.

Overflow error

Each computer has a predefined limit, for example, 16-bit registers. What is the largest number that could be stored in a 16-bit register? If a number larger than this is generated in a process, an overflow error will occur.

20 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


1  Data representation

Logical binary shifts Another process than can occur with binary numbers that are stored in a register is called a logical binary shift. This kind of shift can move the binary values in the number to the left or to the right. Consider the binary number: 0

0

1

0

1

1

0

0

If a logical binary shift to the left is performed on the binary number, each value in the binary number is moved one place to the left. The result would be: 0

1

0

1

1

0

0

0

1

0

1

FT

You should notice that the left most 0 has been removed from the register. This is because there was no place to the left to shift this value. You should also notice that there is now an empty section in the register at the right. When a binary number is shifted, the resulting empty sections are filled with a 0. 1

0

0

0

If you convert the first binary number to denary, you get the denary number 44. If you convert the binary number after the logical left shift has been performed, you get the denary number 88. This means that each logical shift to the left multiples the binary number by 2.

0

0

1

A

Consider the binary number again: 0

1

1

0

0

If a logical shift to the right is performed on the binary number, each value in the binary number is moved one place to the right. The result would be: 0

1

0

1

R

0

1

0

You should notice that the right most 0 has been removed from the register. This is because there was no place to the right to shift this value. You should also notice that there is now an empty section in the register at the left. When a binary number is shifted, the resulting empty sections are, again, filled with a 0. 0

0

1

D

0

0

1

1

0

You already know that the first binary number converted to a denary number is 44. If you convert the binary number after the logical right shift has been performed, you get the denary number 22. This means that each logical shift to the right divides the binary number by 2. Consider another binary number: 1

1

1

0

1

1

0

0

When a logical left shift is performed on the binary value the result is: 1

1

0

1

1

0

0

0

21 Original material Š Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


CAMBRIDGE IGCSE™ & O-LEVEL COMPUTER SCIENCE: COURSEBOOK

When the first binary number is converted to a denary number, the result is 236. When the binary number is converted after the logical shift to the left has been performed, the denary value is 216. You should notice that 236 multiplied by 2 is not 216. Therefore, one of the problems with a logical shift is that data can lose its integrity as vital bits can be removed from the register. More than one logical shift can be performed on a register. For example, two logical shifts to the left can be performed. This time, each value in the register is shifted two places to the left. The binary value: 1

1

1

0

1

1

0

0

1

1

0

0

0

0

1

0

Questions 5 6

FT

would become:

Describe what happens in a logical binary shift. Perform two logical shifts to the right on the binary number 11101100

Negative binary numbers

R

A

All the binary numbers that you have used so far have been positive binary numbers. Numbers can sometimes be negatives number though, for example, −150. How are negative numbers represented as binary? Binary only has two values that can be used, a 0 and a 1, so you can’t just put a minus symbol (−) in front of the number, as that symbol doesn’t exist in binary. Therefore, a method exists that can be used to represent negative binary numbers and it is called two’s compliment. Most modern computers use this method. The method of two’s compliment is a simple one. First you invert all the values in the binary number (change the 1s to 0s and the 0s to 1s), then you add 1 to the result. You can use this process to find out how the denary value −35 is represented as binary.

D

Convert 35 to a binary number: 0

0

1

0

0

0

1

1

Invert each of the values in the binary number: 1

1

0

1

1

1

0

0

0

1

1

1

0

1

Then simply add 1: 1

1

11011101 is the binary representation of −35 using the two’s compliment method.

22 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


1  Data representation

1.3 How do computers represent text, images and sound? You have already learnt that computers only process binary. This means that all data must be converted to binary to be processed by a computer. You have already looked at converting numbers, but text, images and sound all have to be converted to binary too, so they can be processed by a computer. How is this done?

Converting text to binary

KEY WORDS character set: it contains all the characters that are in that character set and the binary value that is assigned to each character.

FT

When a computer converts text to binary to be processed it uses a tool called a character set. There are two main types of character set that a computer can use, ASCII and Unicode. An ASCII character set represents characters using 8-bit binary numbers. This means that it can represent up to 256 characters (0 to 255). This is fine for certain languages, but some languages have an alphabet that requires more than 256 characters; therefore, Unicode was invented. A Unicode character set represents characters using 16-bit binary numbers. This means it can represent a much greater number of characters, approximately 65 000. This means that many more characters can be developed in different alphabets and also symbols such as emojis can also be used.

ACTIVITY 1.2

A

Each character has a set binary value, for example, the letter A is 01000001.

Use the internet to find an example of an ASCII character set and a Unicode character set. What kind of different characters are represented? Are upper and lowercase letters the same?

R

Using the ASCII table, try to decode this message:

01000011011011110100110101110000011101010111010001100101011100 100101001101

D

10001101101001010001010110111001100011011001010110100101110011 011001100111 01010110111000100001

Remember, each letter will be represented as an 8-bit binary number. Try writing a message for your friend to decode.

Converting images to binary

KEY WORD

An image is made up of tiny dots called pixels. If an image was simply created using the colours black and white, each pixel would be either black or white. The binary value 1 could be used to represent the colour black and the binary value 0 could be used to represent the colour white.

pixel: a very small dot of colour that is displayed with many other to create an image.

23 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


CAMBRIDGE IGCSE™ & O-LEVEL COMPUTER SCIENCE: COURSEBOOK

If each pixel is converted to its binary value, a data set such as the following could be created: 0011111000100000101000000011001010011000000011010001011001110010100000100 01111100 If the computer is informed that the image that should be created using this data is 9 pixels wide and 10 pixels high. It can set each pixel to black or white and create the image (See Figure 1.2). The type of data that is used to provide information, such as the dimensions and resolution of an image, is called metadata.

KEY WORDS resolution: the dimensions of an image.

R

A

FT

metadata: additional data that is stored with an image that can provide information such as the dimensions of the image and the time and date the image was taken.

Figure 1.2: An image created just from black and white pixels

D

Most images use a lot more colours than black and white. Each colour has its own binary values. Colours are created by computer screens using the RGB colour system. This system mixes the colours red, green and blue in different amounts to achieve each colour.

ACTIVITY 1.3

Use the internet to find an RGB colour scale. You should notice that each colour in the scale is first presented as hexadecimal. The first two hexadecimal values are the amount of red, the second two the amount of blue and the last two the amount of green. Practise your hexadecimal to binary conversion by converting your favourite colour to its binary value.

24 Original material Š Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


1

Most images are created using thousands of pixels. Each of those pixels needs quite a lot of data. Multiply that by the thousands of pixels that make up the image and that is a huge amount of data. This is why image files can often be so large in size. Each image has a resolution and a colour depth. The resolution is the number of pixels wide and the number of pixels high that are used to create the image. The colour depth is the number of bits that are used to represent each colour. For example, each colour could be represented using 8-bit, 16-bit or 32-bit binary numbers (see Figure 1.3). The greater the number of bits, the greater the range of colours that can be represented.

Data representation

KEY WORDS colour depth: the number of bits that are used to create each colour in an image

16-bit colour

32-bit colour

A

Figure 1.3: 8-bit colour

FT

If the colour depth of an image is reduced, the quality of the image is often reduced.

Can you see how the quality of the image is reduced in comparison to the number of bits used?

R

If the resolution or the colour depth of an image is changed, this will have an effect on the size of the image file. If the resolution is increased, the image will be created using more pixels, so more data will need to be stored. If the colour depth of the image is increased, each pixel will need more data to display a greater range of colours so more data will need to be stored. Both will result in a larger file size for the image.

D

COMPUTER SCIENCE IN CONTEXT

People often have to sacrifice the quality of their images when displaying them online. This is because having files that are very large in size can take more time to download. This may frustrate any user as it may mean they have to wait for a website to load, due to the number of large files it contains.

Converting sound to binary Sound is made up of sound waves. When sound is recorded, this is done at set time intervals. This process is known as sound sampling. Figure 1.4 is an example of a sound wave:

KEY WORDS sound sampling: a little piece of sound that is recorded at regular time intervals.

25 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


CAMBRIDGE IGCSE™ & O-LEVEL COMPUTER SCIENCE: COURSEBOOK

Sound values

15

10

5

0

0

1

2

3

4

5 6 7 Time samples

8

9

10

11

12

Figure 1.4: A sound wave

Time sample

1

2

3

4

Sound value

9

13

9

3.5

FT

If you recorded the sound at each time sample, you would have the following set of values: 5

6

7

8

9

10

11

12

4

9

1.5

9

8

5

8

5.5

Each sound value is converted to binary to be processed by the computer. Each sound value is then used to playback the sound, when the recording is played. If the recorded sound wave is played it would now look like Figure 1.5:

A

10

5

0

0

R

Sound values

15

1

2

3

4

5 6 7 Time samples

8

9

10

11

12

D

Figure 1.5: A sound wave created by playing back a recorded sound

You will notice that the two sound waves look different. This is because the number of samples taken is too far apart, so vital data in between time samples has been lost. This will result in a lack of accuracy in the sound that is recorded. Therefore, more samples need to be taken each second to improve the accuracy of the recorded sound. The number of samples taken in a second is called the sample rate. Sample rates are measured in hertz. 1 hertz is equal to 1 sample per second. A common sample rate is 44.1 khz (kilohertz), this would require 44 100 samples to be taken each second. That is a lot of data! If the sample rate is increased, the amount of data required for the recording is increased. This increases the size of the file that stores the sound. Further data is required to represent sound, and this is the sample resolution. This is the number of bits that are used to represent each sample. A common sample resolution is 16-bit. The higher the sample resolution, the greater the variations in amplitude that can be stored for each sample. This means that aspects such as the

KEY WORDS sample rate: the number of samples recorded each second. sample resolution: the number of bits that are used to record each sound sample.

26 Original material Š Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


1  Data representation

loudness of the sound can be recorded more accurately. This will also increase the amount of data that needs to be stored for each sample. This increases the size of the file that stores the sound.

1.4 Measuring data storage Earlier in the chapter, you learnt that all data need to be converted to digital data to be processed by a computer, and you now know how that is done for different types of data. But how is data measured when it is stored?

COMPUTER SCIENCE IN CONTEXT

FT

There are times when you will need to know the size of a data file, such as when you are attaching a file to an email. Most email providers have a file size limit, so you need to know the size of that file, to know if it can be attached to your email.

Data is measured using different units, which are shown in Table 1.2: Description

Bit

This is the smallest measurement for data

Nibble

There are 4 bits in a nibble

Byte

A

Unit

There are 8 bits in a byte

Kibibyte (KiB) Mebibyte (MiB) Gibibyte (GiB)

There are 1024 Kibibytes in a Mebibyte

There are 1024 Mebibytes in a Gibibyte There are 1024 Gibibyte in a Tebibyte

R

Tebibyte (TiB)

There are 1024 bytes in a Kibibyte

Pebibyte (PiB)

There are 1024 Tebibytes in a Pebibyte

Exbibyte (EiB)

There are 1024 Pebibytes in an Exbibyte

Table 1.2: Data measuring units

D

Although most computers will calculate the size of a file for you, you need to be able to show that you can do this manually for the exam. This is just for an image file and a sound file.

SKILLS FOCUS 1.3

CALCULATING THE SIZE OF A FILE There are several pieces of information that you need to know to calculate the size of an image file, these are: • • •

the number of images in the file the resolution of the image the colour depth of the image.

27 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


CAMBRIDGE IGCSE™ & O-LEVEL COMPUTER SCIENCE: COURSEBOOK

CONTINUED When you know this information, you can perform a simple calculation to get the size of the image file, which is: width of image × height of image × colour depth of image × number of images in file Therefore, if you have the following information about an image file: • • •

10 images in the file image resolution is 100 × 150 colour depth is 8-bit colour,

you can calculate the size of the image file as follows:

FT

• 100 × 150 = 15,000 (this means there are 15 000 pixels in the image) • 15 000 × 8 = 120,000 (this means that there are 120 000 bits in each image) • 120 000 × 10 = 1 200 000 (this means there are 1 200 000 bits in the image file). You will be asked to calculate the size of an image file to a certain unit of measurement. The answer given here (1 200 000) is the number of bits that are in the image file. If you wanted to know how many bytes are in the image file, you need to divide the final answer by 8, as there are 8 bits in each byte, for example: 1 200 000 ÷ 8 = 150 000 bytes

A

If you wanted to know how many kibibytes the file was, you need to divide the answer in bytes by 1024, for example: 150 000 ÷ 1024 = 146.5 KiB (to 1 decimal place) Questions 1

R

How many times would you need to divide the answer in bytes by 1024 to find the answer in Gibibytes? 2 How many pixels would there be in an image that has a resolution of 1000 × 1500? There are several pieces of information that you need to know to calculate the size of a sound file, these are:

D

• the length of the soundtrack • the sample rate of the soundtrack • the sample resolution of the soundtrack. When you know this information, you can perform a simple calculation to get the size of the sound file, which is: sample rate × sample resolution × length of soundtrack

Therefore, if you have the following information about a sound file: • • •

length of 30 seconds sample rate of 44,100 hz sample resolution of 8 bits,

you can calculate the size of the sound file as follows: • •

44 100 × 8 = 352 800 (this means there are 352 800 bits per second) 352 800 × 30 = 10 584 000 (this means there are 10 584 000 bits in the sound file).

28 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


1  Data representation

CONTINUED You will be asked again to calculate the size of a sound file to a certain unit of measurement. The answer given (10 584 000) is the number of bits that are in the sound file. If you wanted to know how many bytes are in the sound file, you need to divide the final answer again by 8, as there are 8 bits in each byte, for example: 10 584 000 ÷ 8 = 1 323 000 bytes If you wanted to know how many mebibytes the file was, you need to divide the answer in bytes by 1024, then by 1024 again, for example: 1 323 000 ÷ 1024 ÷ 1024 = 1.3 MiB (to 1 decimal place)

FT

1.5 Data compression

You may already have experience of having large files and struggling to have enough storage space to store them. One thing that can be done to reduce the size of a file is compression.

Compressing a file will reduce the size of the file that can have several benefits, such as: Not as much storage space is needed to store the file.

It will take less time to transmit the file from one device to another.

It will be quicker to upload and download the file.

Not as much bandwidth is needed to transmit the file over the internet.

A

There two type of compression that can be used, lossy and lossless. Each compresses the data in a different way.

R

Lossy compression uses a compression algorithm that finds the unnecessary and redundant data in the file. This data is permanently removed from the file. This type of compression is mainly used on an image file or a sound file.

D

Unnecessary data in an image file that could be removed are colours that the human eye cannot distinguish. This means that a lossy compression algorithm for an image file could reduce the size of the file by reducing the colour depth. It could also reduce the size of the file by reducing the image resolution, reducing the number of pixels used to create the image.

Unnecessary data in a sound file that could be removed are sounds that cannot be heard by the human ear. It could also be the removal of softer sounds that are played at the same time as louder sounds, as humans will only hear the louder sound. The method that is used to find these kinds of sounds in a sound file is called perceptual music shaping. This is the most common type of method that is used in the file format MP3. The size of a sound file can also be reduced by reducing the sample rate and the sample resolution.

Questions 7 8 9

Why do you think lossy compression is not commonly used on text files? Will lossy compression affect the quality of an image? Why? Will lossy compression affect the quality of a sound recording? Why?

KEY WORDS compression: a method that uses an algorithm to reduce the size of a file. lossy: a compression method that reduces the size of a file by permanently removing data. lossless: a compression method that reduces the size of a file by temporarily altering the data.

KEY WORDS perceptual music shaping: a process that is used in lossy compression that removes sounds that are not normally heard by the human ear.

29 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


CAMBRIDGE IGCSE™ & O-LEVEL COMPUTER SCIENCE: COURSEBOOK

SELF ASSESSMENT What were the points that you thought about regarding lossy compression to answer question 7? Did you relate these points back to why lossy compression is not suitable for a text file, or did you just make points about the drawbacks of lossy compression in general?

Lossless compression uses a compression algorithm to reduce the size of the file, without permanently removing any data. A common method that can be used to do this is by finding repeating data in the file and grouping this data together. For example, consider the following message:

FT

WHEN IT IS SNOWING HEAVILY LOOK OUTSIDE. LOOK OUTSIDE IT IS SNOWING HEAVILY.

Excluding the spaces between the words and the full stops, the message has a total of 62 characters. 1 character requires 1 byte of storage, so 62 bytes of storage would be needed to store this message. When you look at the message, you should notice that it consists of words that are mostly repeated. Instead of storing all 62 characters individually, the words and the positions at which they occur in the message can be stored in a lookup table, for example: Position(s) in the message

WHEN IT

A

Word

1

2, 10

IS

3, 11

SNOWING

5, 13

R

HEAVILY

4, 12

LOOK

6, 8

OUTSIDE

7, 9

D

The lookup table needs 1 byte for each character in each word and 1 byte for each position the word occurs in the message. Therefore, 33 bytes are needed to store the words and 13 bytes to store the positions, giving a total of 46 bytes. This is much less than the 62 bytes we required with our original method. No data has been lost and we have reduced our storage requirements by 26%, quite a saving! To recreate the message, the computer simply retrieves the words and places them in the positions allocated. A similar process can be applied to an image file with a lossless compression algorithm called run length encoding (RLE). This algorithm will group together repeating pixels and store how many times they occur. For example, consider the simple image in Figure 1.6:

30 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


A

Figure 1.6: A simple pixel image

FT

1  Data representation

If W is white, Y is yellow, R is red and G is green, RLE could compress the image into the following data:

R

12W, 3Y, 5W, 2Y, 1R, 2Y, 3W, 2Y, 3R, 2Y, 3W, 2Y, 1R, 2Y, 5W, 3Y, 7W, 1G, 5W, 2G, 1W, 1G, 1W, 2G, 4W, 3G, 7W, 1G, 4W. This means that the amount of data can be reduced as pixels are grouped together and the data for each pixel does not need to be stored. The resolution of the image is stored with the data, so that the computer knows the size to recreate it when the data is decompressed.

D

ACTIVITY 1.4

Why don’t you try creating a simple image and writing out the RLE data for it? You could then give it to your friend, along with the image resolution, and they can have fun trying to recreate your image. Peer Assessment Ask your friend whether you got the RLE correct for your image in Activity 1.4. Ask them if you could have done anything to make your RLE any clearer. Ask them if you missed any important data.

31 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


CAMBRIDGE IGCSE™ & O-LEVEL COMPUTER SCIENCE: COURSEBOOK

SUMMARY Computers require any data to be converted to binary before it can be processed by the computer. Different number systems exist such as denary, binary and hexadecimal. Hexadecimal is used in computer science for uses such as aiding programmers and representing MAC addresses. Binary numbers can be added using four rules. If this creates a result greater than 255 for 8-bit binary numbers, an overflow error occurs. Logical binary shifts can be performed on binary numbers. These can shift left or shift right and can be done multiple times. This changes the binary number and can affect the accuracy of the binary number. Text is converted to binary using a character set such as ASCII or Unicode.

FT

Images are converted to binary by taking each pixel and providing it with a colour code that is converted to a binary value. The larger the resolution and colour depth of an image, the greater the amount of data that will need to be stored in the image file. This also increases the quality of the image. Sound is converted to binary by sampling the sound at a set time interval. The value of each sound sample is converted to binary. The greater the sample rate and resolution of the sound, the greater the amount of data that will need to be stored in the sound file. This also increases the accuracy of the recording. Data is measured in different units such as bits, bytes and mebibytes.

A

Data can be compressed, using lossy or lossless compression, to reduce the size of a file. This means it will take up less storage space and it can be quicker to transmit the file.

EXAM-STYLE QUESTIONS

COMMAND WORDS state: express in clear terms. describe: state the points of a topic / give characteristics and main features.

D

R

1 There are two different types of data, known as analogue data and digital data. a State what is meant by analogue data. [1] b State what is meant by digital data. [1] [Total: 2] 2 Describe the difference between a denary number system and a binary number system. [4] [Total: 4] 3 A music venue has a small display screen built into the top of each seat. The display screen displays the number of the seat. Each seat number is displayed as hexadecimal. a Convert the two given seat numbers into 12-bit binary values. [4] • 21A • 90D b Write the seat number that would be displayed for the binary number 000010011100. [2] [Total: 6] 4 Two registers store the given 8-bit binary values. Register 1 stores 00110111 and register 2 stores 01110011. a Add the two binary values and write the result of the calculation. Show all your working. [3]

32 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


1  Data representation

CONTINUED

8

show (that): provide structured evidence that leads to a given result. calculate: work out from given facts, figures or information.

FT

7

A

6

COMMAND WORDS

give: produce an answer from a given source or recall/ memory. explain: set out purposes or reasons / make the relationships between things evident / provide why and/or how and support with relevant evidence.

R

5

b A logical left shift of three places is performed on Register 1. Write the contents of register 1 after the logical shift has been performed. [1] [Total: 4] Show how the value −28 is represented in binary using two’s compliment. Show all your working. [2] A student wants to store some images that they have taken with their digital camera. They do not have enough storage space on their external hard disk drive to store the images at their current file size. a State how the student can reduce the amount of data stored for each image. [1] b The student has 20 images to store, that have a resolution of 150 × 250 and a colour depth of 16-bit. Calculate the size of the file that will store the images in MiB. [3] [Total: 4] A blogger displays images of their daily life on their blog. They also have sound files of hints and tips that they record available on their blog. a The blogger compresses the images that they display on their blog. Give two benefits of compressing an image file. [2] b The blogger uses lossless compression to compress the sound file on their blog. Explain how lossless compression will compress the sound file that the blogger makes available on their blog. [4] [Total: 6] Four file sizes are given. Tick () to show which file size is the largest. File size

Tick () the largest file size

1 GiB

2033 bytes

D

1050 MiB 1500 KiB

[1]

SELF-EVALUATION CHECKLIST

After studying this chapter, think about how confident you are with the different topics. This will help you to see any gaps in your knowledge and help you to learn more effectively. You might find it helpful to rate how confident you are for each of these statements when you are revising. You should revisit any topics that you rated ‘Needs more work’ or  ‘Getting there’.

33 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


CAMBRIDGE IGCSE™ & O-LEVEL COMPUTER SCIENCE: COURSEBOOK

CONTINUED See topic...

explain why data needs to be converted to binary to be processed by a computer.

1.1

convert between denary numbers and binary numbers.

1.1

convert between denary numbers and hexadecimal.

1.1

convert between binary numbers and hexadecimal.

1.1

provide examples of the use of hexadecimal in computer science.

1.1

explain why hexadecimal is used in computer science.

1.1

add two 8-bit binary numbers.

1.2

Needs more work

Getting there

Confident to move on

FT

I can …

1.2

perform a logical binary shift on a binary number, including left and right shifts and multiple shifts.

1.2

use two’s compliment to represent negative numbers.

1.2

explain how character sets are used by a computer to represent text.

1.3

explain how pixels are used by a computer to create images.

1.3

explain how the file size of an image is affected by the image resolution and colour depth.

1.3

explain how a sound wave is sampled by a computer.

1.3

explain how the file size of a sound recording is affected by the sample rate and sample resolution.

1.3

understand how the size of a data file is measured.

1.4

calculate the size of an image file.

1.4

calculate the size of a sound file.

1.4

understand the need for data compression and the effect it has on a file.

1.5

explain how different types of data are compressed using lossy compression.

1.5

explain how different types of file are compressed using lossless compression.

1.5

D

R

A

explain what is meant by an overflow error.

34 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


Chapter 2

R

A

FT

Data transmission

D

IN THIS CHAPTER YOU WILL: •

learn how data is broken down into packets to be transmitted, including the contents of each packet

understand how data is transmitted using a range of different transmission methods

be able to choose a data transmission method for a given scenario

learn about the universal serial bus (USB) interface and how it is used to transmit data

learn how errors can occur when transmitting data

be able to describe how a range of different error detection methods work

understand why it is useful to encrypt data when it is transmitted

be able to describe how data is encrypted using both symmetric and asymmetric encryption.

Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


CAMBRIDGE IGCSE™ & O-LEVEL COMPUTER SCIENCE: COURSEBOOK

GETTING STARTED Your data is transmitted to other devices, sometimes all over the word, on a regular basis. Have you thought about how it gets there? Draw a diagram to represent how you think data travels from your device to your friend’s device, when you send them a message. It doesn’t matter if you don’t think you know how this is done, just draw what you think happens and you can see at the end of the chapter how close you were with your diagram.

DATA TRANSMISSION IN THE FINANCIAL WORLD

R

A

FT

A bank has to transmit data all around the world for thousands, possibly millions, of people on a daily basis. The accuracy of this data is imperative. Imagine what would happen if one person’s hard earned money went into another person’s bank account! When data is transmitted, there are certain things that can cause it to suffer errors. Interference is a big issue in data transmission that can cause errors in the data, therefore banks have to make sure that they have many error detection methods in place to make sure that data is accurate, even after transmission. As the accuracy of the data is so crucial for banking transactions, banks have to combine Figure 2.1: Financial transactions can be done online several types of error detection, to make sure that the data has been thoroughly and completely analysed for errors.

D

The importance of checking for errors in data transmission can costs banks a lot of money. It takes very large and powerful systems to check the millions of transactions that are made every day. However, it would cost them even more in compensation money, if they messed up the data of their customers, and possibly their money, so they put a lot of time, money and effort into the process. Discussion questions 1

How would you feel about having a bank account with a bank that did not have any error detection systems in place? What problems do you think this could cause?

2

Do you think it is right that the bank is responsible for checking errors in the transmission of data? Much of the hardware, that will be used to transmit the data from one device to another, will not be owned by them. So, why do you the bank should be made responsible for checking for errors if the errors may occur using hardware that isn’t theirs?

36 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


2  Data transmission

2.1 The structure of a data packet The amount of data that is stored in a file can be very large. If you tried to transmit this data from one device to another, all at once, this just wouldn’t be possible or practical. The wires or radio waves used would simply not be able to accommodate sending such large amounts of data at a single time. Therefore, for the data in a file to be transmitted, it is broken down into very small units called packets. Each packet of data contains three different sections: Packet header Payload Trailer

destination address

packet number

originators address.

packet: a small unit of data. packet header: a section of a packet of data that contains information about the contents of the packet and its destination.

FT

The packet header contains a lot of important information about the data enclosed in the packet and its destination. The information it includes is the:

KEY WORDS

The destination address is normally an IP address. It is the IP address of the device where the data is being sent. Without this address, the hardware transmitting the data would not know where to send the data.

A

Each data packet in the file is given a packet number. The packets of data may not have all been sent in the correct order, this will depend on the type of transmission used; you will learn more about this in Sections 2.2 and 2.3. This means that when the destination device has received all the data packets, it can use the packet number to put them back into the correct order to recreate the file.

R

The originators address is also normally an IP address. It is the IP address of the device from which the data has been originally sent. So, if you send data to another device, the originator’s address is the address of your device. This address isn’t crucial to the transmission process, but it does help to trace where data has been sent from in situations such as illegal activity, or to simply request the original device to resend the data if an error is detected.

D

The payload of the data packet is the actual data from the file that you are sending. The data is broken up into many small units to be sent as the payload in each packet. The trailer section of the packet is sometimes known as the footer. This contains two main pieces of information. The first is the marker to indicate it is the end of the packet and also the data for any error detection systems that are being used. You will learn more about this in Section 2.2.

Questions 1 2 3 4

Can you name the three main sections of a data packet? What information does the packet header contain? Which part of the data packet is the actual data from the file? Why does data need to be broken down into packets to be transmitted?

KEY WORDS payload: the actual data that the user is sending to the receiver. trailer: a section of a packet of data that contains information about any error checking methods that may be used.

37 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


CAMBRIDGE IGCSE™ & O-LEVEL COMPUTER SCIENCE: COURSEBOOK

ACTIVITY 2.1 Ask your teacher if you are allowed to use a packet tracer. Your teacher may want to complete this activity together as a class. Use the packet tracer to send data to another device and look at the data that the packet tracer software provides. What kind of information does it give you? What route did your packets take to get to the destination device?

2.2 Packet switching

KEY WORDS packet switching: a method of transmitting data packets across a network. Each data packet is able to take an individual pathway across the network.

FT

You have learnt that data is broken down into packets to be sent from one device to another. The process of transmitting these packets is called packet switching. In this process, each packet of data is sent individually from one device to another. There could be several pathways across a network that the packets could be transmitted. Each data packet could be sent along a different pathway. A router is the device that controls which pathway will be used to transmit each packet. You will learn more about how a router does this later in the chapter. Look at the diagram of a network in Figure 2.2:

Router 1

Router 3

R

Device A

A

Router 2

network: computers and devices that are joined together using cables or wireless technology.

Device B

D

Router 4

Router 5

router: a network component that examines a data packet to obtain its destination address and then forward the packet to this address.

Figure 2.2: A network

The packets of data start at device A, they could be transmitted down any of the pathways between device A and device B. Each packet can be sent using a different pathway. When a packet reaches a router, the router decides which pathway to send the packet along next. This will continue until all the packets have arrived at device B. It is likely that the packets will arrive out of order. Once all packets have arrived, they are reordered to recreate the file.

38 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


2  Data transmission

ACTIVITY 2.2 Five packets of data need to be sent from device A to device B. The pathway the first packet takes is: •

Router 1

Router 2.

Router 1

Router 4

Router 5.

The pathway the third packet takes is: •

Router 1

Router 3

Router 2.

Router 1

Router 4

Router 3

Router 5.

A

The pathway the fourth packet takes is:

FT

The pathway the second packet takes is:

R

The pathway the fifth packet takes is: •

Router 1

Router 3

Router 5.

D

Draw a copy of the diagram of a network. Use coloured pens to draw the pathway that each of the packets of data takes. Self Assessment What did you do to check if your diagram is correct? Have you tried tracing each route to see if it goes through the correct routers?

39 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


CAMBRIDGE IGCSE™ & O-LEVEL COMPUTER SCIENCE: COURSEBOOK

2.3 Methods of data transmission You might think that there is only one method that can be used to transmit data from one device to another, but there are actually several. You need to understand how data is transmitted using each of these methods. These include: •

serial

parallel

simplex

half-duplex

full-duplex.

KEY WORDS

Serial data transmission

In serial data transmission, data is transmitted using a single wire. Each bit of data is transmitted one at a time along the single wire. Figure 2.3 shows an example:

1

1

0

0

parallel: a transmission method where data is sent multiple bits at a time down multiple wires.

Device B

A

Device A

serial: a transmission method where data is sent one bit at a time down a single wire.

FT

Serial and parallel data transmission involve the number of wires that are used to transmit the data, and how many bits of data are sent at a time.

Each bit of data is transmitted one at a time along a single wire

R

Figure 2.3: Serial data transmission

There are several advantages and disadvantages of serial data transmission, see Table 2.1: Advantages

Disadvantages

D

As data is sent one bit at a time, it As data is sent one bit at a time, the should arrive in order of sequence. This transmission of data is slower. means there is less chance of the data being skewed. As data is sent along a single wire, there is less chance of interference. This means there is less chance of error in the data.

Additional data may need to be sent to indicate to the receiving device when the data transmission has started and stopped. These are called a start bit and a stop bit.

Only one wire is needed for a serial transmission cable, therefore, it is cheaper to manufacture and also cheaper to buy.

KEY WORD interference: disruption, such as electromagnetism, to data when it is transmitted.

Table 2.1: Advantages/disadvantages of serial data transmission

40 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


2  Data transmission

Serial transmission has less chance of data being skewed and less chance of interference. This makes it more suitable for the transmission of data over long distances.

Parallel data transmission In parallel data transmission, data is transmitted using multiple wires. Multiple bits of data are transmitted along each wire at the same time. Figure 2.4 shows an example: 0

1

1

1

1

0

0

0

1

1

0

1

1

1

0

0

0

1

1

0

1

1

0

0

0

1

1

Device B

FT

Device A

1

1 0 0 1

Multiple bits of data are transmitted at the same time, along multiple wires

A

Figure 2.4: Parallel data transmission

There are several advantages and disadvantages of parallel data transmission, see Table 2.2: Advantages

Disadvantages

As data is sent multiple bits at the same time, bits do not arrive in order and need to be reordered after transmission. This increases the risk of the data being skewed.

Many computers and devices use parallel data transmission to transmit data internally. Therefore, there is no requirement to convert this to serial data transmission to transmit the data across a network.

As data is sent along multiple wires, there is more chance of interference. This means there is more chance of error in the data.

D

R

As data is sent multiple bits at the same time, the transmission of data is quicker.

Multiple wires are needed for a parallel transmission cable, therefore, it is more expensive to manufacture and also more expensive to buy.

Table 2.2: Advantages/disadvantages of parallel data transmission

Parallel transmission has an increased chance of data being skewed and an increased chance of interference. This makes it more suitable for the transmission of data over shorter distances. This is often limited to approximately 5 metres.

41 Original material Š Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


CAMBRIDGE IGCSE™ & O-LEVEL COMPUTER SCIENCE: COURSEBOOK

Question 5

A marketing company prints leaflets to deliver to people’s houses. The leaflets are designed on a computer and sent to a large printer that is 3 metres away. Large numbers of leaflets need to be printed in a short period of time, to makes sure that they are ready for delivery. Would you use a serial or a parallel data transmission cable to connect the computer to the printer? Why would you choose this type of cable?

Simplex, half-duplex and full-duplex transmission involve the direction in which the data is transmitted.

In simplex data transmission, data is transmitted from one device to another in one direction only. Figure 2.5 shows an example:

Device A

Device B

A

Figure 2.5: Simplex data transmission

simplex: a transmission method where data is transmitted in a single direction only.

FT

Simplex data transmission

KEY WORDS

full-duplex: a transmission method where data is transmitted in both directions at the same time.

D

R

You would only use this type of data transmission when there is no need to send data both ways between the devices. One example is connecting a keyboard to a computer. Simplex data transmission can be used to do this as data only needs to be sent from the keyboard to the computer, so that the computer screen can display the keys that are pressed. There is no reason why the computer would need to send data to the keyboard, so a simplex data transmission connection is used.

half-duplex: a transmission method where is transmitted in both directions, but only one direction at a time.

Figure 2.6: Simplex data transmission is used between a computer and a keyboard

42 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


2  Data transmission

Half-duplex data transmission In half-duplex data transmission, data can be transmitted in both directions between the devices, but only one direction at a time. Figure 2.7 shows an example:

Device A

Device B

FT

If data is being transmitted from Device A to Device B, then data cannot be transmitted from Device B to Device A, at the same time.

Device A

Device B

A

If data is being transmitted from Device B to Device A, then data cannot be transmitted from Device A to Device B, at the same time. Figure 2.7: Half-duplex data transmission

R

You would use this type of data transmission when you need to send data in both directions between the devices, but there is no requirement for this to be at the same time. It can also be used when the communication between two devices needs to have a high level of performance. This is when two half-duplex connections can be set up between devices to allow data to be transmitted in both directions at the same time, but using two different channels of communication. Can you work out how this would be set up?

D

ACTIVITY 2.3

Use the internet to research how half-duplex data transmission is used to create a Wi-Fi connection. Why is half-duplex, rather than full-duplex data transmission used in Wi-Fi connections?

Figure 2.8: Wi-fi uses halfduplex data transmission

Full-duplex data transmission In full-duplex data transmission, data is transmitted can be transmitted in both directions between the devices, at the same time. Figure 2.9 shows an example:

43 Original material Š Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


CAMBRIDGE IGCSE™ & O-LEVEL COMPUTER SCIENCE: COURSEBOOK

Device A

Device B

Figure 2.9: Full-duplex data transmission

FT

You would use this type of data transmission when it is imperative that data needs to be both sent and received by each device, at the same time. One example is a telephone conversation. The person speaking into Device A can speak at the same time as the person speaking into Device B. It may be a little bit of a chaotic conversation if you both try and speak at the same time all the time though! However, during most conversations, people do sometimes speak at the same time, so full-duplex data transmission is needed.

When a connection is created between two different devices it will either be a serial or parallel data connection. It will also be a simplex, half-duplex or full-duplex connection. This means that a connection can be, for example, a serial simplex connection, or a parallel half-duplex connection, or possibly a serial full-duplex connection. You need to understand when each of the different methods of transmission are most suitable.

Questions 6 7 8

D

R

A

Which method of data transmission sends data along a single wire? Which method of data transmission sends data multiple bits at a time? If a data transmission connection sends data one bit at a time, in both directions, but not at the same time, what kind of data transmission methods are used? 9 What are two advantage of serial data transmission? 10 What are two disadvantages of parallel data transmission? 11 A business manager transmits data about its customers to a central file server. The file server is 100 meters away from the business manager’s office. They need to be able to send and receive customer data to and from the server, at the same time. The accuracy of the customer’s data is imperative. Which methods of data transmission should be used to create the connection between the business manager’s computer and the file server? Why would you choose those methods?

ACTIVITY 2.4

Write a data transmission scenario like the one given in Question 6. Think about which data transmissions methods could be used for your scenario and why they would be the most suitable. Peer Assessment Give the scenario to a friend and ask them which data transmissions methods they would use. Are they the same methods that you thought should be used? If you have chosen different methods, discuss and come to an agreement about which methods should be used. If you chose the same methods, see if you had the same reasons for choosing those methods.

44 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


2  Data transmission

2.4 The universal serial bus (USB) interface The concept of USB can be a little confusing, as it is used to describe several aspects. You may have heard of a USB connection, you may have heard of a USB cable, you may simply just call a storage device a USB. You need to understand the difference between several of these aspects. A USB interface includes items such as a USB port, a USB cable, a USB connection and a USB device. A USB device, such as a USB memory stick, is a type of storage device that uses the USB interface. The storage device plugs into a USB port on a computer and it transmits data using a USB connection. A USB cable can be used to connect devices, such as a mouse, to a computer.

USB port: a socket that is a part of a device or computer that enables you to insert a USB cable. USB cable: a type of transmission media that uses the USB method to transmit data.

FT

A USB connection uses serial data transmission to transmit data between the devices. However, it a special type of serial data transmission connection that is used that is designed to transmit data at high speeds.

KEY WORDS

ACTIVITY 2.5

A

One of the issues with serial data transmission is the transmission speed is slower than parallel. Research how a USB connection is able to transmit data at a faster rate.

COMPUTER SCIENCE IN CONTEXT

USB device: the name of a device that plugs into a USB port on a computer.

R

Many devices are connected using a USB cable. This is because the USB interface is an industry standard, which means that manufacturers don’t need to worry about compatibility issues when connecting devices. One of the most recent versions of the USB interface to be released is USB 4.

USB connection: a collective name for using a USB cable plugged into a USB port to transfer data from one device to another.

ACTIVITY 2.6

D

Research the data transfer speed of USB 4; is this different to USB 1, 2 and 3? What other differences can you find between the different versions of USB?

There are several advantages and disadvantages of the USB interface, see Table 2.3: Advantages

Disadvantages

It is a simple interface. The USB cable The length of a USB cable is limited, to device can only fit into the USB one normally to 5 meters. way. Therefore, it means less errors in connecting devices are likely to be made. The speed of a USB connection is relatively high, so data can be transferred quickly.

The transmission speed is relatively high for a USB connection, but it isn’t as high as other types of connection, such as ethernet.

KEY WORD ethernet: another type of connection that can be used to transmit data within a network.

45 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


CAMBRIDGE IGCSE™ & O-LEVEL COMPUTER SCIENCE: COURSEBOOK

Advantages

Disadvantages

The USB interface is a universal standard for connecting devices, therefore a USB port is included in many different devices. When a USB device to cable is inserted into a USB port, it is automatically detected. The first connection will normally involve the download of drivers to operate the hardware that has been connected. Each connection after this the driver should not need to be downloaded again.

FT

A USB connection can also be used to power a device, so it does not need another power source. It can also use this to charge a device, such as a mobile phone.

Table 2.3: Advantages/disadvantages of the USB interface

Questions

A

What does USB stand for? What type of data transmission method does a USB interface use? What are two advantages of using the USB interface? Can you name 5 devices that are connected using a USB interface? What is the length a USB cable limited to? Can you think why it is limited to this length?

R

12 13 14 15 16

2.5 Detecting errors in data transmission

D

The transmission of data from one device to another is often not a perfect process. In the process of transmitting the data interference can occur. This can cause data to be lost, data to be gained and data to change. This would not be helpful and could also lead to many issues. If a password wasn’t transmitted correctly, then that person may not be able to log into their account. If a person’s address wasn’t transmitted correctly, they may not get email that needs to be sent to them. If a person’s details are not transmitted correctly to a company, they may not get a product or service that they order. The accuracy of data is often vital, therefore there needs to be a procedure in place to detect any errors in data so that actions can be taken to correct this.

Figure 2.10: Procedures need to be in place to handle errors in data transmission

46 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


2  Data transmission

There are several error detection methods that can be used, these include: •

parity check

checksum

echo check.

Each of these methods is designed to check for errors after the data has been transmitted from one device to another.

KEY WORDS

A parity check can use an odd or even check method. Each byte of data has 7 bits and 1 extra bit that is called a parity bit (see Figure 2.11). The parity bit is normally the first or last bit of data in the byte.

parity check: a type of error detection method that adds an additional bit to each byte to create an odd or even sum.

1 0 0 1 0 0 0 1

Parity bit

FT

Parity check

7 bits of data

Figure 2.11: The parity bit is the first bit of data in this byte

R

A

Before transmission begins, the parity check is set to be either odd or even parity. The number of 1s in the 7 bits of data are totalled. In the example in Figure 2.11, the result of that would be 2. If an odd parity check is used, then a 1 is added as a parity bit. This is because all the 1s in the byte now add up to 3, which is an odd number. If an even parity check is used a parity bit of 0 would have been added instead. This is because all the 1s in the byte would then add up to 2, which is an even number. When the parity bit has been added to each byte, the data can be transmitted. After transmission, the receiving device will check each byte of data for errors. If an odd parity check has been used and the device finds a byte that has an even number of 1s, then it knows that an error has occurred with this byte of data. The error is detected!

D

Questions

17 Which of these bytes would have been transmitted incorrectly if an even parity check has been used? a 10111011 b 01110111 c 10101000 18 Which of these bytes would have been transmitted incorrectly if an odd parity check has been used? a 00110001 b 10110101 c 10001000 19 Can you think of an instance in which an error could occur in the data, but this would not be detected by a parity check?

47 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


CAMBRIDGE IGCSE™ & O-LEVEL COMPUTER SCIENCE: COURSEBOOK

Checksum

KEY WORD

A checksum uses a calculated value to check for errors. A value is calculated from the data that will be transmitted, before transmission takes place. A method such as modulus 11 could be used to calculate the value.

ACTIVITY 2.7 Use the internet to find out how the modulus 11 method calculates a value from the data. You do not need to be able to remember how to do this method of calculation for the exam, but it will help you to know how a checksum is calculated.

checksum: a type of error detection method that performs a calculation on the data to create a checksum value. Checksum values are compared after transmission to see if they match.

FT

Once the checksum value has been calculated it is added to the data to be transmitted with it. After transmission, the receiving device uses the same method to calculate a value from the received data. If the values match, then the device knows that no error has occurred during transmission. If the values do not match, the device knows that an error has occurred during transmission. The error is detected!

Questions

Echo check

A

20 What is the checksum value calculated from? 21 What happens to the checksum value when it has been calculated before transmission? 22 Why would checksum values that do not match show that an error has occurred?

D

R

An echo check involves a simple comparison of the data sent to the data received. The sending device transmits the data to the receiving device. The receiving device then transmits the data it receives back to the sending device. The sending device compares the data it sent to the data it has received back from the receiving device to see if they match. If they do, then no error has occurred. If they don’t match, then the sending device knows the data was received with error. The error is detected!

KEY WORDS echo check: a type of error detection method that sends a copy of the transmitted data back to the sender to be compared with the original data sent.

ACTIVITY 2.8

Draw a diagram to represent how an echo check detects errors in data.

Question 23 If the data does not match that which is sent back by the receiving device, will this always mean that the receiving device did not receive the data correctly? How do you know that?

48 Original material © Cambridge University Press 2020. This material is not final and is subject to further changes prior to publication.


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.