1. SWE – 105T
INTRODUCTION TO COMPUTING
Software Engineering Department
Sir Syed University of Engineering & Technology
NUMBER SYSTEM AND
CONVERSIONS
1
2. Numbers
• Natural Numbers
Zero and any number obtained by repeatedly
adding one to it.
Examples: 100, 0, 45645, 32
• Negative Numbers
A value less than 0, with a – sign Examples: -24, -1, -
45645, -32
2
3. Numbers (Cont’d)
• Integers
A natural number, a negative number, zero
Examples: 249, 0, - 45645, - 32
• Rational Numbers
An integer or the quotient of two integers Examples:
-249, -1, 0, ¼ , - ½
3
4. Understanding Number System
• The radix, or base, of a number system is the total
number of unique symbols available in that
system.
• The largest valued symbol always has a magnitude
of one less than the radix.
• The study of binary system will help us gain better
understanding of how computers perform
computation.
4
6. Types of Number System
There are various types of number system which as
follows:
Decimal Number System
Binary Number System
Octal Number System
Hexadecimal Number System
6
7. Types of Number System
• Four most commonly used number systems are-
7
8. Number System
• The following table shows the base and digits
used in these number systems-
Number System Base Digits Used
Decimal Number
System
10
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
(Total 10 digits)
Binary Number
System
2
0, 1
(Total 2 digits)
Octal Number
System
8
0, 1, 2, 3, 4, 5, 6, 7
(Total 8 digits)
Hexadecimal
Number System
16
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B,
C, D, E, F
(Total 16 digits)
8
10. Binary Number System
• Binary Number System
– It is the simplest form of number system. It consists of only
two digits in base which are 0 and 1 or on and off
respectively
– They are used as the numbering system for computers. A
binary number can be easily represented by using a series
of switches
– Each single digit in the binary system is called as a bit.
When four bits are combined together a nibble is formed
– Eight bits or two nibbles are combined to form a byte.
Sixteen bits or two bytes combine to form a word and
similarly thirty two bits or two words are called as a
double word
10
11. Binary Number System
• The following is the diagrammatic representation of
binary number system:
11
12. Binary Numbers (cont.)
Decimal Binary
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
10 1010
1 0 1 0
8 4 2 1
Considering the digits that
has a value of 1 and adding
it number marker on the
top of each digits
8 + 2 = 10
12
14. Decimal Number System
Decimal system consists of 10 digits starting from 0
to 9. This number system has ten as its base.
14
15. Decimal Number System
• In number system,
• It is very important to have a good knowledge of
how to convert numbers from one base to
another base.
• Here, we will learn how to convert any given
number from any base to base 10.
15
16. Decimal Number System
• Converting to Base 10-
• A given number can be converted from any base
to base 10 using Expansion Method.
• According to expansion method, if abc.de is any
given number in base x, then its value in base 10
is given as-
(abc.de)x = (ax2 + bx + c + dx-1 + ex-2)10
16
17. Decimal Number System
• Explanation-
• To use expansion method for conversion,
• Assign position number to each digit of the given number.
• Digits to the left of decimal are numbered starting from 0.
• Digits to the right of decimal are numbered starting from -1.
• Write a term for each digit as digit x (base of given
number)position number of digit
• Perform the addition of all terms to obtain the number in base
10.
• This formula can be expanded for any number of digits.
17
19. Decimal to Binary Conversion( Base 10 to
base 2)
• In number system,
• It is very important to have a good knowledge of
how to convert numbers from one base to
another base.
• Here, we will learn how to convert any given
number from base 10 to base 2.
19
20. Explanation
• Steps To Convert From Base 10 To Base 2-
• Multiply the given fraction (in base 10) with 2.
• Write the real part and fractional part of the result so
obtained separately.
• Multiply the fractional part with 2.
• Write the real part and fractional part of the result so
obtained separately.
• Repeat this procedure until the fractional part remains 0.
• If fractional part does not terminate to 0, find the result up
to as many places as required.
20
21. Decimal to Octal Conversion( Base 10 to Base
8)
• In number system,
• It is very important to have a good knowledge of
how to convert numbers from one base to
another base.
• Here, we will learn how to convert any given
number from base 10 to base 8.
21
22. Explanation
• Steps To Convert From Base 10 To Base 8
• Multiply the given fraction (in base 10) with 8.
• Write the real part and fractional part of the result so
obtained separately.
• Multiply the fractional part with 8.
• Write the real part and fractional part of the result so
obtained separately.
• Repeat this procedure until the fractional part remains 0.
• If fractional part does not terminate to 0, find the result up
to as many places as required.
22
23. Decimal to Hexadecimal Conversion( Base 10
to base 16)
• In number system,
• It is very important to have a good knowledge of
how to convert numbers from one base to
another base.
• Here, we will learn how to convert any given
number from base 10 to base 16.
23
24. Explanation
• Steps To Convert From Base 10 To Base 16
• Multiply the given fraction (in base 10) with 16.
• Write the real part and fractional part of the result so obtained
separately.
• Multiply the fractional part with 16.
• Write the real part and fractional part of the result so obtained
separately.
• Repeat this procedure until the fractional part remains 0.
• If fractional part does not terminate to 0, find the result up to as
many places as required.
24
25. Octal Number System
• Octal Number System
It is one of the most commonly used number
system in computers. It is used in programming
because of its similarity to binary number system
A single octal digit is equal to three binary digits.
Octal Number System uses the base as 8.
• Base 8
• Ten Digits: 0, 1, 2, 3, 4, 5, 6, 7
• Example: 238
25
26. Hexadecimal Number System
• Hexadecimal Number System
This number system is used for larger numbers.
Hexadecimal number system uses the base as 16
In hexadecimal number system the number 0 to 9
are denoted normally then the numbers 10 to 15
are denoted by alphabets A through F
respectively.
26
27. ASCII Code
• ASCII Code
– The American Standard Code for Information Interchange (ASCII)
code is a special form of BCD code that is widely used in digital
computers and data communications equipment.
– It is a 7-bit binary code that is used in transferring data between
computers and their external peripheral devices and in
communicating data by radio and telephone lines.
– The ASCII code is used to represent the 26 upper case letters (A to Z),
26 lowercase letters (a to z), 10 numbers (0 to 9), 33 special
characters and symbols and 33 control characters
– They are considered as a standard code for denoting character as
binary numbers which is used in computer terminals, printers and
microcomputers
– If a file is saved in ASCII format it can be easily used by another
application
27
28. Conversion of the Number System
• Binary to Decimal , Octal, Hexadecimal
• Decimal to Binary, Octal, Hexadecimal
• Octal to Decimal, Binary, Hexadecimal
• Hexadecimal to Binary, Octal, Decimal
28
30. Binary to Decimal
• Remember that Binary numbers are based on the radix of 2
while Decimal numbers are based on the radix of 10.
• Remember also that binary will only be represented in 1s and
0s.
• Steps in converting Binary to Decimal:
– Place a number marker on the top of the given digits, starting
from 0 up the last given digits—starting from the right to
determine the exponent to use.
– Consider all the 1s in the given digits and multiply it with the
base number of the given digits (which is base 2) and raised it
with power of the number corresponded in the number marker
you placed on the top of the given digits.
30
31. Example: Binary to Decimal
1010102 = ?10
= 101010
= 1*25
+ 1*23
+ 1*21
= 32 + 8 + 2
= 4210
5 4 3 2 1 0
Place the number marker
on the top of the given
digits, starting from the
right, starting from 0 up to
the last given digit on the
left.
31
32. Example: Binary to Decimal
• (10010)2 → ( ? )10
Using expansion method, we have-
(10010)2
= ( 1 x 24 + 0 x 23 + 0 x 22 + 1 x 21 + 0 x 20 )10
= ( 16 + 0 + 0 + 2 + 0 )10
= ( 18 )10
32
33. Example: Binary to Decimal
• (10010.101)2 → ( ? )10
Using expansion method, we have-
(10010.101)2
= ( 1 x 24 + 0 x 23 + 0 x 22 + 1 x 21 + 0 x 20 + 1 x 2-1 + 0 x 2-
2 + 1 x 2-3 )10
= ( 16 + 0 + 0 + 2 + 0 + 0.5 + 0.125 )10
= ( 18.625 )10
33
34. Binary to Octal
• Since one octal digit is equivalent to three binary digits, just
group three binary digits, starting from the least significant bit
(right side).
• Append 0 to the most significant bit (left side), if the grouping
does not have enough to form three binary digits.
• In short, you must complete the grouping of three digits.
• If you will be having a fraction (decimal point), append 0 to
the least most significant bit (right side) of the given digits to
complete the grouping of three bits.
34
35. Binary to Octal (cont.)
• Steps in converting Binary to Octal:
– Group the given digits in three starting from the
right side.
– If the grouping is not complete, place 0 to
complete the grouping.
– Once you have grouped it into three digits, you
starting converting the binary digits into decimal
values following the concepts of binary digits (4, 2,
1) starting from the right.
35
37. Example: Binary to Octal
(1101010)2 = ?8
= 001 101 010
= 001 101 010
= 1 5 28
= 1528
1st group
2nd group
3rd group
4 2 1
4 2 1
4 2 1
Add 0 to the left, to
complete the
grouping
Simply add all the
number markers
considering the
binary digits that has
1 on it.
37
38. Example: Binary to Octal
(1010)2=( ? )8
Split the binary number from left to right each group
3 bits
001 010
1 2
(1010)2=(12)8
38
39. Example: Binary to Octal
(111110011001)2= ?8
Split the binary number from left to right each
group 3 bits
111 110 011 001
7 6 3 1
(111110011001)2=(7631)8
39
40. Binary to Hexadecimal
• Since one hexadecimal digit is equivalent to four binary digits,
just group four binary digits, starting from the least significant
bit (right side).
• Append 0 to the most significant bit (left side), if the grouping
does not have enough to form four binary digits.
• In short, you must complete the grouping of four digits.
• If you will be having a fraction (decimal point), append 0 to
the least most significant bit (right side) of the given digits to
complete the grouping of three bits.
40
41. Binary to Hexadecimal (cont.)
• Steps in converting Binary to Hexadecimal:
– Group the given digits in four starting from the right
side.
– If the grouping is not complete, place 0 to complete
the grouping.
– Once you have grouped it into three digits, you
starting converting the binary digits into decimal
values following the concepts of binary digits (8, 4, 2,
1) starting from the right.
41
43. Example: Binary to Hexadecimal
(1101010)2 = ?16
= 0110 1010
= 0110 1010
= 6 A16
= 6A16
1st group
2nd group
8 4 2 1
Add 0 to the left, to
complete the
grouping
Simply add all the
number markers
considering the
binary digits that has
1 on it.
8 4 2 1
43
44. Example: Binary to Hexadecimal
10101110112 = ?16
10 1011 1011
2 B B
10101110112 = 2BB16
44
45. Decimal to Binary
• Converting a decimal number to a binary number
is done by successively dividing the decimal
number by 2 on the left side of the radix.
• If you will have a fractional part of the given
decimal, successively multiplying the decimal
number by 2 on the right side of the radix.
45
46. Decimal to Binary (cont.)
• Steps in converting Decimal to Binary:
– Divide the given decimal number with the base
number you are converting it to, which is 2.
– Whatever the answer you will get in the division will
be divided again with the base (2) until you cannot
divide the answer anymore with 2.
– The remainder that you will get will be the one you
consider as your converted answer.
46
48. Example: Decimal to Binary
• (18)10 → ( ? )2
• Using division method, we have-
• From here, (18)10 = (10010)2
48
49. Example: Decimal to Binary
• (172)10 → ( ? )2
• Using division method, we have-
• From here, (172)10 = (10101100)2
49
50. Decimal to Octal
• Converting a decimal number to an octal number
is done by successively dividing the decimal
number by 8 on the left side of the radix.
• If you will have a fractional part of the given
decimal, successively multiplying the decimal
number by 8 on the right side of the radix.
50
51. Decimal to Octal (cont.)
• Steps in converting Decimal to Octal:
– Divide the given decimal number with the base
number you are converting it to, which is 8.
– Whatever the answer you will get in the division will
be divided again with the base (8) until you cannot
divide the answer anymore with 8.
– The remainder that you will get will be the one you
consider as your converted answer.
51
53. Example: Decimal to Octal
• (1032)10 → (?)8
• Using division method, we have-
• From here, (1032)10 = (2010)8
53
54. Example: Decimal to Octal
• (172)10 → ( ? )8
• Using division method, we have-
• From here, (172)10 = (254)8
54
55. Decimal to Hexadecimal
• Converting a decimal number to a hexadecimal
number is done by successively dividing the
decimal number by 16 on the left side of the radix
• If you will have a fractional part of the given
decimal, successively multiplying the decimal
number by 16 on the right side of the radix.
55
56. Decimal to Hexadecimal (cont.)
• Steps in converting Decimal to Hexadecimal:
– Divide the given decimal number with the base number you are
converting it to, which is 16.
– Whatever the answer you will get in the division will be divided
again with the base (16) until you cannot divide the answer
anymore with 16.
– The remainder that you will get will be the one you consider as
your converted answer.
56
58. Example: Decimal to Hexadecimal
• (2020)10 → (?)16
• Using division method, we have-
• From here, (2020)10 = (7E4)16
58
59. Example: Decimal to Hexadecimal
• (172)10 → ( ? )16
• Using division method, we have-
• From here, (172)10 = (AC)16
59
60. Octal to Decimal
• Remember that Octal numbers are based on the radix of 8 while Decimal
numbers are based on the radix of 10.
• Remember also that Octal will only be represented with value 0-7.
• Steps in converting Octal to Decimal:
– Place a number marker on the top of the given digits, starting from 0 up the
last given digits—starting from the right to determine the exponent to use.
– Considering all the given digits, multiply it with the base number of the
given digits (which is base 8) and raised it with power of the number
corresponded in the number marker you placed on the top of the given
digits.
60
61. Example: Octal to Decimal
(761)8 = ?10
= 761
= 7*82
+ 6*81
+ 1*80
= 56 + 48 + 1
= 10510
2 1 0
Place the number marker
on the top of the given
digits, starting from the
right, starting from 0 up to
the last given digit on the
left.
61
62. Example: Octal to Decimal
(254)8 → ( ? )10
Using expansion method, we have-
(254)8
= ( 2 x 82 + 5 x 81 + 4 x 80 )10
= ( 128 + 40 + 4 )10
= ( 172 )10
62
63. Example: Octal to Decimal
(254.7014)8 → ( ? )10
Using expansion method, we have-
(254.7014)8
= ( 2 x 82 + 5 x 81 + 4 x 80 + 7 x 8-1 + 0 x 8-2 + 1 x 8-3 + 4 x 8-4 )10
= ( 128 + 40 + 4 + 0.875 + 0.0019 + 0.0009 )10
= ( 172.8778 )10
63
65. Octal to Binary
• Since one octal digit is equivalent to three binary
digits, just convert the individual octal digit into
three binary digits.
• Steps in converting Octal to Binary:
– Convert each of the given octal number by simply
using the concept of (4, 2, 1).
– Place a binary 1 to correspond the given octal
number.
65
66. Example: Octal to Binary
(761)8 = ?2
= 7 111
= 6 110
= 1 001
= 111 110 0012
4 2 1
4 2 1
4 2 1
Simply add all the number
markers considering the
binary digits that has 1 on
it, to get the octal number
given.
66
68. Octal to Hexadecimal
• When converting an octal digit to a hexadecimal digit, you
must first convert the octal number to binary number and
group it by four and convert the grouped digits to
hexadecimal by using the concept of (8, 4, 2, 1).
• If the digits is not enough to form a grouping of four then
append 0 on the left side of the digits.
• If the given octal have fraction, then append 0 on the right
side of the given digits.
68
69. Octal to Hexadecimal (cont.)
• Steps in converting Octal to Hexadecimal:
– Convert the octal digits in binary by considering each
given digits and represent it in binary using the
concept (4, 2, 1).
– Once it is in binary, that’s the time you convert the
binary into hexadecimal, by grouping it into four.
69
72. Hexadecimal to Binary
• Since one hexadecimal digit is equivalent to four
binary digits, just convert the individual
hexadecimal digit into four binary digit
72
73. Example: Hexadecimal to Binary
(7AE3)16 = ?2
= 7 0111
A 1010
E 1110
3 0011
= (0111 1010 1110 0011)2
73
74. Example: Hexadecimal to Binary
10AF16 = ?2
1 0 A F
0001 0000 1010 1111
10AF16 = 00010000101011112
74
75. Hexadecimal to Octal
• When converting an hexadecimal digit to an octal digit, you
must first convert the hexadecimal number to binary number
and group it by three and convert the grouped digits to octal
by using the concept of (4, 2, 1).
• If the digits is not enough to form a grouping of three then
append 0 on the left side of the digits.
• If the given hexadecimal have fraction, then append 0 on the
right side of the given digits.
75
76. Hexadecimal to Octal (cont.)
• Steps in converting Hexadecimal to Octal:
– Convert the hexadecimal digits in binary by
considering each given digits
– Once converted to binary group the binary into three
and using the concept (4, 2, 1).
76
78. Example: Hexadecimal to Octal
1F0C16 = ?8
1 F 0 C
0001 1111 0000 1100
1 7 4 1 4
1F0C16 = 174148
78
79. Hexadecimal to Decimal
• Each hexadecimal position is weighted with a power of 16.
• Digits on the left side of the radix point has a positive
exponent while on the right side of the radix point has a
negative exponent.
• Converting a hexadecimal number to a decimal number is
done by successively multiplying the decimal number by 16
on the left side of the radix
• If you will have a fractional part of the given decimal,
successively multiplying the decimal number by 16 on the
right side of the radix.
79
80. Hexadecimal to Decimal (cont.)
• Steps in converting Hexadecimal to Decimal:
– Place a number marker on the top of the given
number for determining the exponent to be used.
– Get the individual digit and multiply it by the base
number (16) and raised it with the exponent
corresponds to the number marker you place on each
digit, then to the addition operation.
80
82. Example: Hexadecimal to Decimal
(AC)16 → ( ? )10
Using expansion method, we have-
(AC)16
= ( A x 161 + C x 160 )10
= ( 10 x 16 + 12 x 1 )10
= ( 160 + 12 )10
= ( 172 )10
82
83. Example: Hexadecimal to Decimal
(AC.FBA5)16 → ( ? )10
Using expansion method, we have-
(AC.FBA5)16
= ( A x 161 + C x 160 + F x 16-1 + B x 16-2 + A x 16-3 + 5 x 16-4 )10
= ( 10 x 16 + 12 x 1 + 15 x 16-1 + 11 x 16-2 + 10 x 16-3 + 5 x 16-4 )10
= ( 160 + 12 + 0.9375 + 0.0429 + 0.0024 + 0.0001 )10
= ( 172.9829 )10
83