IGCSE - Computer Science - Trial
IGCSE - Computer Science - Trial
2
Data Representation
Number systems
▪ basic building block in all computers is the binary number system
(consists of 1s and 0s)
▪ computers contain millions and millions of tiny ‘switches’, which must
be in the ON or OFF position
▪ they can be represented by the binary system
▪ Switch ON for 1
▪ Switch OFF for 0
4
Denary system (decimal):
▪ counts in multiples of 10
▪ uses ten separate digits, 0-9, to represent all values
▪ known as a base 10 number system
5
Binary number system:
▪ a base 2 number system (based on the number 2)
▪ only the two values 0 and 1 can be used to represent all values
▪ known as a base 2 number system
6
Converting from binary to denary
▪ each time a 1-value appears in a binary number column, the column
value (heading) is added to a total
E.g.1.
Convert the binary number, 11101110, into a denary number. (8-bit)
128 64 32 16 8 4 2 1
1 1 1 0 1 1 1 0
The equivalent denary number is
128 + 64 + 32 + 8 + 4 + 2 = 238
7
E.g.2.
Convert the binary number, 011110001011, into a denary number.
(12-bit)
0 1 1 1 1 0 0 0 1 0 1 1
8
E.g.3. Convert the binary number, 0011000111100110, into a denary
number. (16-bit)
0 0 1 1 0 0 0 1 1 1 1 0 0 1 1 0
9
10
Converting from denary to binary
Method 1: successive subtraction of powers of 2
▪ in each stage, subtract the largest possible power of 2 and keep doing
this until the value 0 is reached
E.g.1. Convert a denary number 142 into binary number.
142 – 128 = 14;
14 – 8 = 6; 128 64 32 16 8 4 2 1
6 – 4 = 2; 1 0 0 0 1 1 1 0
2–2=0
11
Method 2: successive division by 2
▪ start with the denary number
▪ divide it by 2
▪ write the result of the division including the remainder (even if it is 0)
▪ then divide again by 2 and keep dividing until the result is zero
▪ finally write down all the remainders in reverse order
12
13
E.g.2. Convert a denary number 59 into 8-bit binary number.
Method 1:
59 – 32 = 27;
27 – 16 = 11
11 – 8 = 3;
3 – 2 = 1;
1–1=0
128 64 32 16 8 4 2 1
0 0 1 1 1 0 1 1
14
Method 2:
2 59
2 29 Remainder: 1
2 14 Remainder: 1
2 7 Remainder: 0
2 3 Remainder: 1
2 1 Remainder: 1
2 0 Remainder: 1
15
E.g.3. Convert a denary number 35 000 into 16-bit binary number.
Method 1:
35000 – 32768 = 2232;
2232 – 2048 = 184
184 – 128 = 56
56 – 32 = 24
24 – 16 = 8
8–8=0
16
Method 2:
Binary number:
1000 1000 1011 1000
17
18
The hexadecimal system (simply ‘hex’):
▪ very closely related to the binary system
▪ a base 16 system and needs to use 16 different ‘digits’ to represent
each value
▪ the numbers 0 to 9 and the letters A to F are used to represent each
hexadecimal (hex) digit
▪ A in hex = 10 in denary, B = 11, C = 12, D = 13, E = 14 and F = 15
4 3 2 1 0
(16 ) (16 ) (16 ) (16 ) (16 )
65536 4096 256 16 1
2 1 F 3 A
19
20
Converting from binary to hexadecimal
▪ starting from the right and moving left, split the binary number into
groups of 4 bits
▪ if the last group has less than 4 bits, then simply fill in with 0s from
the left
▪ take each group of 4 bits and convert it into the equivalent
hexadecimal digit
22
23
Converting from hexadecimal to binary
▪ take each hexadecimal digit
▪ write down the 4-bit code which corresponds to the digit
E.g.3. Convert a hexadecimal number 45A to binary number.
4 5 A
0100 0101 1010
26
E.g.1. Convert the hexadecimal number, 4 5 A, into denary.
2 1 0
(16 ) 256 (16 ) 16 (16 ) 1
4 5 A
(4 × 256 = 1024) (5 × 16 = 80) (10 × 1 = 10)
1024 + 80 + 10 = 1114
E.g.2. Convert the hexadecimal number, C 8 F, into denary.
2 1 0
(16 ) 256 (16 ) 16 (16 ) 1
C 8 F
(12 × 256 = 3072) (8 × 16 = 128) (15 × 1 = 15)
3072 + 128 + 15 = 3215
27
28
Converting from denary to hexadecimal
▪ successive division by 16 until the value 0 is reached
E.g.1. Convert the denary number, 2004, into hexadecimal.
16 2004
16 125 Remainder: 4
16 7 Remainder: 13 (D)
0 Remainder: 7
29
E.g.2. Convert the denary number, 8463, into hexadecimal.
16 8463
16 528 Remainder: 15 (F)
16 33 Remainder: 0
16 2 Remainder: 1
0 Remainder: 2
30
31
Addition of binary numbers
▪ addition of two binary digits:
binary addition carry sum
0+0 0 0
0+1 0 1
1+0 0 1
1+1 1 0
32
Cont.
▪ addition of three binary digits:
binary addition carry sum
0+0+0 0 0
0+0+1 0 1
0+1+0 0 1
0+1+1 1 0
1+0+0 0 1
1+0+1 1 0
1+1+0 1 0
1+ 1 + 1 1 1
33
E.g.1. Add 00100111 + 01001010
00100111
+
01001010
111 (carry values)
0 1 1 1 0 0 0 1 (sum values)
Answer: 0 1 1 1 0 0 0 1
34
E.g.2. (a) Convert 126 and 62 into binary.
(b) Add the two binary values in part a and check the result matches
the addition of the two denary numbers.
(a) 126 = 0 1 1 1 1 1 1 0
62 = 0 1 1 1 1 1 0
(b)
01111110
Checking
+
0111110 10111100
111111 (carry values) 128 + 32 + 16 + 8 + 4 = 188
1 0 1 1 1 1 0 0 (sum values)
Answer: 1 0 1 1 1 1 0 0 126 + 62 = 188
35
36
Overflow
▪ the sum has exceeded the original bit value
▪ maximum denary value of an 8-bit binary number is 255 (which is 28 – 1)
▪ the generation of a 9th bit after adding two or more 8-bit binary number is a
clear indication that the sum has exceeded the value
▪ an overflow error is an indication that a number is too big to be
stored in the computer using 8 bits
37
E.g.3. Add 1 1 0 1 1 1 0 and 1 1 0 1 1 1 1 0 using 8 bits.
41
E.g.2. Convert (a) 38 (b) 125 to 8-bit binary numbers using the two’s
complement format.
(a)
-128 64 32 16 8 4 2 1
0 0 1 0 0 1 1 0
(b)
-128 64 32 16 8 4 2 1
0 1 1 1 1 1 0 1
42
Converting positive binary numbers in the two’s complement format
to positive denary numbers
▪ converting a positive binary number to the two’s complement format
can be done exactly the same as using normal successive
multiplication method
64 + 32 + 8 + 4 +2 = 110
43
E.g.4. Convert 0011111 in two’s complement binary into denary.
-128 64 32 16 8 4 2 1
0 0 1 1 1 1 1 1
32 + 8 + 4 +2 + 1 = 63
44
45
Writing negative binary numbers in two’s complement format and
converting to denary
E.g.1. Convert 1 0 0 1 0 0 1 1 in two’s complement binary into denary.
-128 64 32 16 8 4 2 1
1 0 0 1 0 0 1 1
−128 + 16 + 2 + 1 = −109
-128 64 32 16 8 4 2 1
1 1 1 1 0 1 0 1
−128 + 64 + 32 + 16 + 4 + 1 = −11
47
Converting negative denary numbers into binary numbers in two’s
complement format
Convert -67 into 8-bit binary number using two’s complement format.
Method 1:
128-67 = 61
61 – 32 = 29
29 – 16 = 13
13 – 8 = 5 -128 64 32 16 8 4 2 1
5–4=1
1–1=0 1 0 1 1 1 1 0 1
48
Method 2:
▪ first, write the number as a positive binary value
▪ then invert each binary value, which means swapping the 1s and 0s
around
▪ then add 1 to that number
67 – 64 = 3 128 64 32 16 8 4 2 1
3–2=1 0 1 0 0 0 0 1 1
1–1=0 1 0 1 1 1 1 0 0
+1
1 0 1 1 1 1 0 1
49
E.g. 2. Convert −79 into an 8-bit binary number using two’s
complement format.
Method 1:
128 - 79 = 49
49 – 32 = 17
17 – 16 = 1
1–1=0
-128 64 32 16 8 4 2 1
1 0 1 1 0 0 0 1
50
Method 2:
51
E.g. 3. Convert 6 and -6 into an 4-bit binary number using two’s
complement format.
6
-8 4 2 1
0 1 1 0
-6
-8 4 2 1
1 0 1 0
52
E.g. 4. Convert 1676 and -1676 into an 12-bit binary number using
two’s complement format.
53
54