year 10 computer science phase iii work - ark globe academy
TRANSCRIPT
Year10ComputerScienceGCSE
ArkGlobeAcademyPhaseIII–WorkPack11thMay–22ndJune
DataRepresentationThisbookletalongwithdigitalversionsofalltheactivitiesandresourcescanbeaccessedanddownloadedfromwww.arkglobe.orginthestudentresourcessectionoftheVLE.Ifyouareunabletoworkdigitallythenpleasejustworkthroughthisbooklet.Whatyouwillneed
• PenapapertohelpwithworkingoutandactivitiesorComputertocompleteonscreen• CompletetheonlinequizbyFridayeachweek,linkedintheoutcomecolumn(canbe
doneonaphone).
Session Topics Worktobecompleted Outcome
11MayWeek1
Binaryarithmetic
Page26-33Activity–Addingbinarynumbers1Activity–Addingbinarynumbers2Activity–BinaryshiftleftActivity–BinaryShiftrightQuiz:tinyurl.com/datarep04
• Addtwo8bitbinarynumbers
• Recogniseoverflowerrors
• Performbinaryshiftstomultipleanddivide8bitbinarynumbers.
18MayWeek2
Charactersets
Page34–37Activity–ASCIItable1Activity–ASCIItable2Activity–UnicodeQuiz:tinyurl.com/datarep05
• Describetheneedforcharactersets
• DiscussthedifferencebetweenASCII,ExtendedASCIIandUnicode
• Convertcharactersusingacharactersheet
01JuneWeek3
FormativeAssessment
Contact-Foranyquestionsoradditionalsupportcontact:
MrDimitriadis:[email protected]
MrKoramoa:[email protected]
The Ultimate GCSE CS textbook – Chapter 11 Published by paullong.net
© paullong.net 2018 Page 26 of 61 by Paul Long
4) Binary arithmetic
Adding binary numbers
Some binary numbers are easy to add up:
0 + 0 = 0
1 + 0 = 1
0 + 1 = 1
Example – simple binary addition 0 0 1 0 0 0 0 1
+ 0 1 0 1 1 1 0 0
0 1 1 1 1 1 0 1
Activity – adding binary numbers 1
Add the following binary numbers. Show your working.
1) 0 0 1 1
+ 0 1 0 0
2) 0 0 0 1
+ 1 0 0 0
3) 0 0 1 1 0 1 0 1
+ 1 0 0 0 0 0 1 0
4) 1 1 0 1 0 0 1 0
+ 0 0 1 0 1 1 0 1
However, 1 + 1 = 2. Two is not a binary number. It is actually 1 0 (one zero).
Remember this:
1 0
x x
2 1
1 + 0 = 2
Therefore, 1 + 1 is not that simple. It
requires a digit to be carried like in
denary arithmetic.
The Ultimate GCSE CS textbook – Chapter 11 Published by paullong.net
© paullong.net 2018 Page 27 of 61 by Paul Long
Maths Link – adding denary numbers
When you add denary numbers with more than one digit, you have to carry 10s,
100s, 1000s etc.
2 5 3 3 + 8 = 1 1.
+ 4 4 8
1 1 is written in the units column
1 and 1 is carried.
2 5 3 5 + 4 + 1 = 1 0.
+ 4 4 8
0 1 0 is written in the tens column and
1 1 1 is carried.
2 5 3 2 + 4 + 1 = 7.
+ 4 4 8
7 0 1 7 is written in the hundreds column.
1 1
When denary numbers are added, the maximum digit in a column is 9. The next
number is 10 (ten) and so 0 is put in the column with 1 (one) carried to the next
column.
Binary works the same way. The maximum digit in a column is 1. The next number
is 1 0 (one zero) and so if a column adds up to 1 0 (one zero) a 0 (zero) is put in the
column with 1 (one) carried to the next column.
Example – carrying binary numbers 1 1 0 1 1 + 1 = 1 0 (one zero, not ten, denary value 2).
+ 0 0 1
0 0 is written in the ones column
1 and 1 is carried.
1 0 1 0 + 0 + 1 = 1.
+ 0 0 1
1 0 1 is written in the twos column.
1
1 0 1 1 + 0 = 1
0 0 1
+ 1 1 0 1 is written in the fours column.
Check in denary: 5 + 1 = 6 (1 1 0 in binary)
The Ultimate GCSE CS textbook – Chapter 11 Published by paullong.net
© paullong.net 2018 Page 28 of 61 by Paul Long
Video
Watch http://tiny.cc/binaryadd from Khan Academy.
Example – carrying binary numbers 2 0 1 1 1 + 1 = 1 0 (one zero, not ten, denary value 2).
+ 1 1 1
0 0 is written in the ones column
1 and 1 is carried.
0 1 1 1 + 1 + 1 = 1 1 (one one, not eleven).
+ 1 1 1
1 0 1 is written in the twos column.
1 1 and 1 is carried
0 1 1 0 + 1 + 1 = 1 0 (one zero).
+ 1 1 1
1 0 1 0 0 is written in the fours column
1 1 and 1 is carried.
Check in denary: 3 + 7 = 10 (ten, 1 0 1 0 in binary)
Activity – adding binary numbers 2
Add the following binary numbers. Show your working.
1) 0 0 1 1 0 0 0 1
+ 0 0 1 0 0 1 1 0
2) 0 0 1 1 1 0 0 1
+ 1 0 1 1 0 1 0 1
3) 0 0 1 1 0 1 0 1
+ 1 0 1 1 0 1 1 1
4) 0 1 1 1 1 0 1 1
+ 0 0 1 0 1 1 0 1
5) 0 0 1 1 1 1 1 1
+ 1 0 1 1 1 1 1 1
Extension: Use the random number generator to add more binary numbers.
You can check your answers by converting the binary numbers to denary.
The Ultimate GCSE CS textbook – Chapter 11 Published by paullong.net
© paullong.net 2018 Page 29 of 61 by Paul Long
Overflow errors
Imagine you had a field in a database that stored the year in two digit format (eg
18 instead of 2018). Imagine what would happen when adding one to the year
99:
99 + 1 = ?
Is the answer 100, 00 or something else?
Example – millennium bug Before the year 2000, many computer systems used 2 digit dates (eg 94 for 1994).
Every new year, the year is increased by one. But 99 plus one equals 100 which
has 3 digits. This was commonly known as the ‘millennium bug’ which caused
some computers to crash.
A similar problem happens when adding numbers in binary. The largest number
that can be represented by a byte is 255. If only one byte is used for storing
numbers, then an overflow error can occur if binary numbers are added together
resulting in a total bigger than 255.
Example – overflow error 0 1 1 1 1 1 1 1 127 in denary
+ 1 1 0 0 0 0 0 0 192 in denary
1 1 1 1 1 1 So far everything is OK
0 1 1 1 1 1 1 1 1 + 1 = 1 0 (one zero)
+ 1 1 0 0 0 0 0 0
0 1 1 1 1 1 1 0 is written in the column and 1 carried
1
0 1 1 1 1 1 1 1 0 + 1 + 1 = 1 0 (one zero)
+ 1 1 0 0 0 0 0 0
0 0 1 1 1 1 1 1 0 is written in the column and 1 carried
1 1
Now there is a problem. The answer needs to include the 1 that was carried.
However, this would require a 9th bit. As only a byte has been allocated, only 8 bits
are available and so there is an overflow error.
The Ultimate GCSE CS textbook – Chapter 11 Published by paullong.net
© paullong.net 2018 Page 30 of 61 by Paul Long
Binary shifts
Binary shifts are used for multiplication and division.
Binary multiplication
Maths Link – multiplying denarys by 10, 100, 1000
To multiply an integer by 10, you shift the number to the left and put a zero in its
place:
5 x 10 = 50
To multiply an integer by 100, you shift the number twice to the left and put 2 zeros
at the end:
5 x 100 = 500
To multiply an integer by 10000, you shift the number 3 places to the left and put 3
zeros at the end:
5 x 1000 = 5000
So in denary (base 10), you would shift to the left and add zeros when multiplying
integers by 10, 100, 1000.
In binary (base 2), you shift to the left and add zeros when multiplying by 2, 4, 8.
This only applies to binary integers.
Example – multiplying binary by 2, 4, 8 To multiply a binary number by 2, put a zero at the end of the number:
1 1 x 2 = 1 1 0 (check: 3 x 2 = 6)
0 0 1 1 0 1 0 1 x 2 = 0 0 1 1 0 1 0 1 0
To multiply a binary number by 4, put two zeros at the end of the number:
1 1 x 4 = 1 1 0 0 (check: 3 x 4 = 12)
To multiply a binary number by 8, put three zeros at the end of the number:
1 1 x 4 = 1 1 0 0 0 (check: 3 x 8 = 24)
This is known as the binary shift left because all bits are moved one place to the
left.
The Ultimate GCSE CS textbook – Chapter 11 Published by paullong.net
© paullong.net 2018 Page 31 of 61 by Paul Long
Example – binary shift left To multiply a binary number by 2, shift 1 place to the left:
0 0 0 1 0 0 0 1
x2 = 0 0 1 0 0 0 1 0 (check: 17 x 2 = 34)
To multiply a binary number by 4, shift 2 places to the left:
0 0 0 1 0 0 0 1
x4 = 0 1 0 0 0 1 0 0 (check: 17 x 4 = 68)
To multiply a binary number by 8, shift 3 places to the left:
0 0 0 1 0 0 0 1
x8 = 1 0 0 0 1 0 0 0 (check: 17 x 8 = 136)
So the general rule for a left shift, is add a zero to the right most side of the binary
number and discard the bit at the left most side of the binary number. However,
this should not be done if the left most bit is a 1 (one).
Activity – binary shift left
Calculate the following. The first number in each question is shown in binary and
the second number is shown in decimal.
1) 0110 x 4 2) 1100 x 8 3) 0101 x 2 4) 1000 x 16
5) 0001 0010 x 8 6) 0101 1110 x 2
Extension:
Each answer should be shown in 8-bit binary format (one byte).
7) 0111 1101 x 4 8) 1011 1011 x 8
9) Explain the problem with your answers to questions 7 and 8.
Binary division
The opposite rule applies for a right shift which is used for division. Add a zero to
the left most side of the binary number and discard the bit at the right most side of
the binary number. This only works for the whole number (integer) part of the
answer as any denary parts are lost.
The Ultimate GCSE CS textbook – Chapter 11 Published by paullong.net
© paullong.net 2018 Page 32 of 61 by Paul Long
Example – binary shift right To divide a binary number by 2, shift 1 place to the right:
0 0 1 0 0 0 1 0
÷2 = 0 0 0 1 0 0 0 1 (check: 34 ÷ 2 = 17)
To divide a binary number by 4, shift 2 places to the right:
0 1 0 0 0 1 0 0
÷4 = 0 0 0 1 0 0 0 1 (check: 68 ÷ 4 = 17)
To divide a binary number by 8, shift 3 places to the right:
1 0 0 0 1 0 0 0
÷8 = 0 0 0 1 0 0 0 1 (check: 136 ÷ 8 = 17)
Activity – binary shift right
Calculate the following. The first number in each question is shown in binary and
the second number is shown in decimal.
1) 0110 ÷ 2 2) 1100 ÷ 4 3) 0100 ÷ 2 4) 1000 ÷ 8
5) 0011 1000 ÷ 8 6) 0101 1110 ÷ 2
Extension:
7) 0001 0011 ÷ 2 8) 1011 1010 ÷ 8
9) Explain the problem with your answers to questions 7 and 8.
Note: a binary shift right is an integer division (DIV) rather than a regular arithmetic
division but you don’t need to know this for the exam.
Video
Watch http://tiny.cc/binaryshift from CatComputerTeacher on YouTube.
The Ultimate GCSE CS textbook – Chapter 11 Published by paullong.net
© paullong.net 2018 Page 33 of 61 by Paul Long
Questions – follow me 1) What is one purpose of a binary shift right? [1]
2) What is one purpose of a binary shift left? [1]
3) Why might you perform a binary shift of 3 places to the left? [1]
4) Why might you perform a binary shift of 2 places to the right? [1]
5) a) Add together the following two 8 bit binary numbers. Express your
response in an 8 bit binary form. [1]
0 1 1 0 0 0 1 1
+ 1 0 1 1 1 1 0 0
b) Identify the problem this addition has created. [1]
c) Explain why this is a problem. [2]
5) a) Perform a two place right shift on the binary number 11001010. [1]
b) Explain the effect of performing this left shift. [2]
The Ultimate GCSE CS textbook – Chapter 11 Published by paullong.net
© paullong.net 2018 Page 34 of 61 by Paul Long
5) Character sets
Computers only work with binary bits. Therefore, all characters need to be
represented by a binary number. A character set is the set of possible characters
that can be represented by a computer system.
ASCII
The American Standard Code for Information Interchange (ASCII) is a set of bit
patterns used for standard characters and control codes. In order that all
applications can understand the data being used, a standard set of character
codes must be used.
Example – ASCII character codes Character Denary Number Binary Number
[Null char] 0 0000 0000
[Horizontal Tab] 9 0000 1001
# 35 0010 0011
+ 43 0010 1011
5 53 0011 0101
A 65 0100 0001
Z 90 0101 1010
a 97 0110 0001
z 122 0111 1011
[Delete] 127 0111 1111
7-bit ASCII
7-bit ASCII is the original character set that was adopted internationally and only
uses 7 bits. Therefore, there are 128 codes from 0 to 127.
Activity – ASCII table 1
Search the World Wide Web for an ASCII table.
What are the denary codes for the following characters and controls?
1) 8 2) P (upper) 3) q (lower) 4) * 5) [Carriage Return]
What are the characters or controls represented by the following denary codes?
6) 27 7) 85 8) 68 9) 49 10) 4
The Ultimate GCSE CS textbook – Chapter 11 Published by paullong.net
© paullong.net 2018 Page 35 of 61 by Paul Long
Sequential codes
Character codes appear in sequence. This means they are in order. Numbers run
from 0 to 9 and letters run from A to Z and a to z. Therefore, it is possible to work
out a character code if a similar character code is already known.
Example – sequential codes You are given these ASCII character codes:
Character ASCII Code
3 51
F 46
r 114
From this, you can work out that the number 4 will have the next ASCII code after
the number 3 which will be 52 (51 + 1). You can also work out that G will have the
next ASCII code after F which will be 47 (46 + 1).
To work out further codes, draw a small table. For example, to work out the code
for the character y:
Character ASCII Code
r 114 you have been told this above
s 115 add 1
t 116 add another 1
u 117 add another 1
v 118 add another 1
w 119 add another 1
x 120 add another 1
y 121 add another 1
The Ultimate GCSE CS textbook – Chapter 11 Published by paullong.net
© paullong.net 2018 Page 36 of 61 by Paul Long
Activity – ASCII table 2
Here are some ASCII character codes:
Character ASCII Code
5 53
P (upper) 80
c (lower) 99
Without using a full ASCII table, work out the denary codes for the following
characters:
1) 2 2) 9 3) t 4) g 5) R 6) B
Without using a full ASCII table, work out the characters for the following character
codes:
7) 49 8) 57 9) 73 10) 88 11) 109 12) 97
Write out the sentence represented by these ASCII denary codes:
67 111 110 103 114 97 116 117 108 97 116 105 111 110 115 44 32 121 111 117 32 100
105 100 32 105 116 33
Extension: write out the sentence represented by these ASCII binary codes:
01010111 01101111 01110111 00100001 00100000 00100000 01010100 01101000
01100001 01110100 00100000 01110111 01100001 01110011 00100000 01101000
01100001 01110010 01100100 00101110
Extension: set your own challenge using the converter at
http://tiny.cc/BinaryConverter
8-bit Extended ASCII
ASCII only uses 128 characters which covers the English alphabet, numbers, basic
symbols and control codes. Extended ASCII was introduced to allow some foreign
characters to be included and additional symbols. One method of Extended
ASCII uses 8 bits and so there are 256 characters available.
Example – extended ASCII Here are some of the foreign characters and symbols available using one method
of 8-bit Extended ASCII:
ü (129) é (130) ç (135) ¬ (170) ½ (171) ¥ (190) ± (241) ¶ (244)
The Ultimate GCSE CS textbook – Chapter 11 Published by paullong.net
© paullong.net 2018 Page 37 of 61 by Paul Long
Unicode
Extended ASCII had many variants and there were still only 256 characters
available. A new character set emerged.
Unicode includes a lot more characters including a wider range of symbols and
characters for many different alphabets.
The first 128 characters (codes 0 to 127) of Unicode are the same as 7-bit ASCII.
After that, Unicode has its own set of codes. For example, character codes 880 to
1023 are Greek characters.
As there are many thousands of Unicode characters, they are usually shown as
hexadecimal codes rather than binary codes.
Activity - Unicode
Search the World Wide Web for a Unicode table. What are the characters
represented by the following codes?
1) 285 (011C) 2) 952 (03B8) 3) 2835 (0B13)
Bits and codes
The number of bits used in a character set determines the number of characters
that are available. For 7-bit ASCII, there are 128 possible characters (27). For 8-bit
ASCII there are 256 possible characters (28).
Unicode has many variations, but the UTF-32 version uses four bytes for each
character. This gives over 4 million possible characters (232)
Questions – follow me 1) Define the term character set. [1]
2) Explain why ASCII is needed. [2]
3) a) How many codes are available in 7-bit ASCII? [1]
b) How many codes are available in 8-bit Extended ASCII? [1]
4) The ASCII code for Q is 81. What is the ASCII code for T? [1]
5) The Unicode code for g is 103. What is the Unicode code for c? [1]
6) Give two reasons why Unicode might be used instead of ASCII. [2]