0% found this document useful (0 votes)
4 views55 pages

IGCSE - Computer Science - Trial

The document provides an overview of number systems used in computers, focusing on binary, denary, and hexadecimal systems. It explains how to convert between these systems, including methods for binary to denary, denary to binary, and hexadecimal conversions. Additionally, it covers binary addition, overflow, and the two's complement method for representing negative integers.

Uploaded by

TDA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views55 pages

IGCSE - Computer Science - Trial

The document provides an overview of number systems used in computers, focusing on binary, denary, and hexadecimal systems. It explains how to convert between these systems, including methods for binary to denary, denary to binary, and hexadecimal conversions. Additionally, it covers binary addition, overflow, and the two's complement method for representing negative integers.

Uploaded by

TDA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Computer Science

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

(104) (103) (102) (101) (100)


10 000 1000 100 10 1

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

(27) (26) (25) (24) (23) (22) (21) (20)


128 64 32 16 8 4 2 1

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)

2048 1024 512 256 128 64 32 16 8 4 2 1

0 1 1 1 1 0 0 0 1 0 1 1

The equivalent denary number is


1024 + 512 + 256 + 128 + 8 + 2 + 1 = 1931

8
E.g.3. Convert the binary number, 0011000111100110, into a denary
number. (16-bit)

32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1

0 0 1 1 0 0 0 1 1 1 1 0 0 1 1 0

The equivalent denary number is


8192 + 4096 + 256 + 128 + 64 + 32 + 4 + 2 = 12 774

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

Binary number: 0011 1011

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

E.g.1. Convert a binary number 1 0 1 1 1 1 1 0 0 0 0 1 to hexadecimal.


1011 1110 0001
B E 1
21
E.g.2. Convert a binary number 1 0 0 0 0 1 1 1 1 1 1 1 0 1 to
hexadecimal number.

10 0001 1111 1101


0010 0001 1111 1101
2 1 F D

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

E.g.4. Convert a hexadecimal number BF08 to binary number.


B F 0 8
1011 1111 0000 1000
24
25
Converting from hexadecimal to denary
▪ take each of the hexadecimal digits and multiply it by the heading
values
▪ add all the resultant totals together to give the denary number
▪ the hex digits A → F need to be first converted to the values 10 → 15
before carrying out the multiplication

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

Hexadecimal number: 7D4

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

Hexadecimal number: 210F

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.

the 8 bits of the answer,


01001100

the denary value,


64 + 8 + 4 = 76
This addition has generated a 9th bit
which is incorrect because
the denary value of the
addition is 110 + 222 = 332
38
39
Two’s complement (binary numbers)
▪ is used to allow the possibility of representing negative integers
▪ the left-most bit is changed to a negative value
▪ for an 8-bit number, the value 128 is now changed to −128, but all the other
headings remain the same
▪ the new range of possible numbers is: −128 (10000000) to +127 (01111111)
▪ when applying two’s complement to a binary number that the left-
most bit always determines the sign of the binary number
▪ a 1-value in the left-most bit indicates a negative number and a 0-
value in the leftmost bit indicates a positive number
▪ for example, 00110011 represents 51 and 11001111 represents −49
40
Converting positive denary numbers to binary numbers in the two’s
complement format
▪ converting a positive denary number to the two’s complement format
can be done exactly the same as using normal successive subtraction
or successive division methods

E.g.1. Convert 19 and 4 into binary numbers in two’s complement


format.
-128 64 32 16 8 4 2 1
0 0 0 1 0 0 1 1
0 0 0 0 0 1 0 0

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

E.g.3. Convert 01101110 in two’s complement binary into denary.


-128 64 32 16 8 4 2 1
0 1 1 0 1 1 1 0

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

Convert 1 1 1 0 0 1 0 0 in two’s complement binary into denary.


-128 64 32 16 8 4 2 1
1 1 1 0 0 1 0 0
−128 + 64 + 32 + 4 = −28
46
Convert 1 1 1 1 0 1 0 1 in two’s complement binary into denary.

-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:

write 79 in binary: 01001111


invert the binary digits: 10110000
add 1 to the inverted number: +1
thus giving −79: 10110001

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

You might also like