3. Number systems
• Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
• Binary – 0, 1
• Octal – 0, 1, 2, 3, 4, 5, 6, 7
• Hexadecimal system – 0, 1, 2, 3, 4, 5, 6, 7, 8,
9, A, B, C, D, E, F
• ASCII
4. Why different number systems?
• Binary number result in quite a long string of
0s and 1s
• Easier for the computer to interpret input
from the user
5. Base Conversion
• In daily life, we use decimal (base 10) number
system
• Computer can only read in 0 and 1
– Number system being used inside a computer is
binary (base 2)
– Octal (base 8) and hexadecimal (base 16) are used
in programming for convenience
10. Binary and decimal system
• Binary to decimal
– X^27 + X^26+ X^25+X ^ 24 + X ^ 23+ X ^ 22+ X ^ 21 + X ^20
• Decimal to binary
– Keep dividing the number by two and keep track
of the remainders.
– Arrange the remainders (0 or 1) from the least
significant (right) to most significant (left) digits
11. Octal and Hexadecimal system
• Binary to Octal (8 = 23)
– Every 3 binary digit equivalent to one octal digit
• Binary to Hexadecimal (16 = 24)
– Every 4 binary digit equivalent to one hexadecimal digit
• Octal to binary
– Every one octal digit equivalent to 3 binary digit
• Hexadecimal to binary
– Every one hexadecimal digit equivalent to 4 binary digits
12. Base Conversion
• How to convert the decimal number to other
number system
– e.g. convert 1810 in binary form
2 |18 ----0
2 |09 ----1
2 |04 ----0
2 |02 ----0
1
– 1810 = 100102
13. Exercise
1-Convert 10001000(2) to Decimal.
2-Convert 1000111.001(2) to Decimal.
3-Convert 6767(10) to Binary.
4-Convert 186(10) to Hexadecimal.
5-Convert 5BD(16) to Decimal.
6-Convert 16AC(16) to Binary.
7-Convert 10001110(2) to Hexadecimal.
8-Convert 196(10) to Octal.
14. Exercise
9-Convert 0216(8) to decimal.
10-Convert 0216(8) to binary.
11-726(8) to decimal.
12-27FB16 to octal.
13-(104)10 to binary
14-(AF)16 to decimal.
15. Base Conversion
For example:
62 = 111110 = 76 = 3E
decimal binary octal hexadecimal
1 For Decimal:
62 = 6x101 + 2x100
2 For Binary:
111110 = 1x25 + 1x24 + 1x23 + 1x22 + 1x21 + 0x20
3 For Octal:
76 = 7x81+ 6x80
4 For Hexadecimal:
3E = 3x161 + 14x160
• Since for hexadecimal system, each digit contains number from 1 to
15, thus we use A, B, C, D, E and F to represent 10, 11, 12, 13, 14
and 15.