ib_number systems and conversions
TRANSCRIPT
-
7/29/2019 IB_Number Systems and Conversions
1/30
Number Systems and Conversions
Abu Ahmed Ferdaus
Assistant ProfessorDepartment of Computer Science & Engineering
Dhaka University
-
7/29/2019 IB_Number Systems and Conversions
2/30
Number Systems and Conversions
Topics:
Overview of number systems Conversions:
1. Decimal to Binary2. Decimal to Octal3. Decimal to Hexadecimal
4. Binary to Decimal5. Binary to Octal6. Binary to Hexadecimal7. Octal to Decimal
8. Octal to Binary9. Octal to Hexadecimal10. Hexadecimal to Decimal11. Hexadecimal to Binary12. Hexadecimal to Octal
Exercises
-
7/29/2019 IB_Number Systems and Conversions
3/30
Overview of Number System
Many number systems are in use in digital
technology. The most common are:1. Decimal number system base 10
(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
2. Binary number system base 2
(0, 1)
3. Octal number system base 8
(0, 1, 2, 3, 4, 5, 6, 7)
4. Hexadecimal number system base 16(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F)
The decimal system is clearly the most familiar to
us because it is a tool that we use every day.
-
7/29/2019 IB_Number Systems and Conversions
4/30
Decimal System
The decimal system is composed of 10 numerals or
symbols. These 10 symbols are 0, 1, 2, 3, 4, 5, 6, 7, 8,9; using these symbols as digits of a number, we canexpress any quantity. The decimal system, also calledthe base-10 system because it has 10 digits.
103
102
101
100
10-1
10-2
10-3
=1000 =100 =10 =1 . =0.1 =0.01 =0.001
MostSignificant
Digit
Decimalpoint
LeastSignificant
Digit
-
7/29/2019 IB_Number Systems and Conversions
5/30
Decimal Numbers
decimal means that we have ten digits to use in our
representation (the symbols 0 through 9)
Decimal number 3,546?
it is threethousands plus fivehundreds plus four
tens plus sixones.
Decimal number: 329
329
102 101 100
3x100 + 2x10 + 9x1 = 329
-
7/29/2019 IB_Number Systems and Conversions
6/30
Binary System
In the binary system, there are only two symbols or
possible digit values, 0 and 1. This base-2 system canbe used to represent any quantity that can berepresented in decimal or other number system.
23
22
21
20
2-1
2-2
2-3
=8 =4 =2 =1 . =1/2 =1/4 =1/8
Most
Significant Bit Binarypoint
Least
Significant Bit
-
7/29/2019 IB_Number Systems and Conversions
7/30
Binary Numbers
Binary (base two) system:
has two states: 0 and 1
Basic unit of information is the binary digit, or bit.
Binary number 101
101
22 21 20
1x4 + 0x2 + 1x1 = 5
most
significant
least
significant
-
7/29/2019 IB_Number Systems and Conversions
8/30
Fractional Values
In Decimal
In Binary
0.329
10-1
10-2
10-3
3x0.1 + 2x0.01 + 9x0.001 = 0.329
0.011
2-1 2-2 2-3
0x0.5 + 1x0.25 + 1x0.125 = 0.375
-
7/29/2019 IB_Number Systems and Conversions
9/30
Octal Number System
The octal number system has a base of eight, meaning
that it has eight possible digits: 0,1,2,3,4,5,6,7.
83
82
81
80
8-1
8-2
8-3
=512 =64 =8 =1 . =1/8 =1/64 =1/512
Most
Significant
Digit
Octal
point
Least
Significant
Digit
-
7/29/2019 IB_Number Systems and Conversions
10/30
Octal Numbers
Octal means that we have eight digits to use in ourrepresentation (the symbols 0 through 7)
Octal number 327 = ?
3x64 + 2x8 + 7x1 = 215
327
81 8082
-
7/29/2019 IB_Number Systems and Conversions
11/30
Hexadecimal Number System
The hexadecimal system uses base 16. Thus, it has 16
possible digit symbols. It uses the digits 0 through 9 plusthe letters A, B, C, D, E, and F as the 16 digit symbols.
163 162 161 160 16-1 16-2 16-3
=4096 =256 =16 =1 . =1/16 =1/256 =1/4096
Most
Significant
Digit
Hexadec.
point
Least
Significant
Digit
-
7/29/2019 IB_Number Systems and Conversions
12/30
Hexadecimal Numbers
Hexadecimal means that we have sixteen digits touse in our representation (the symbols 0 to 9 and
A,B,C,D,E,F)
Hex number 27B = ?
2x256 + 7x16 + 11x1 = 635
27B
161 160162
-
7/29/2019 IB_Number Systems and Conversions
13/30
Comparison of Four Number Systems
Binary
00000001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
Base-2
Octal
01
2
3
4
5
6
7
10
11
12
13
14
15
16
17
Base-8
Decimal
01
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Base-10
Hexadecimal
01
2
3
4
5
6
7
8
9
A
B
C
D
E
F
Base-16
-
7/29/2019 IB_Number Systems and Conversions
14/30
Number Conversion
Number Conversion can be viewed as:
Decimal
HexadecimalOctal
Binary
-
7/29/2019 IB_Number Systems and Conversions
15/30
1. Decimal to Binary Conversion
Repeated Division: repeatedly divide the decimal
number by 2, the base of the binary system. Divisionby 2 will either give a remainder of 1 (dividing an oddnumber) or no remainder (dividing an even number).Collecting the remainders from the repeated divisionswill give the binary answer. Example: convert 25
10to
binary.
25/ 2 = 12+ remainder of 1 1 (Least Significant Bit)
12/ 2 = 6 + remainder of 0 06 / 2 = 3 + remainder of 0 0
3 / 2 = 1 + remainder of 1 1
1 / 2 = 0 + remainder of 1 1(Most Significant Bit)Result 2510 = 1 1 0 0 12
-
7/29/2019 IB_Number Systems and Conversions
16/30
1. Decimal to Binary Conversion (Cont.)
Reading from bottom to top, the final answer is 11001.
Remember that the first division gives us the leastsignificant digit of our answer, and the final divisiongives us the most significant digit of our answer. Also,the result of the final division is always 0.
Converting Fraction: When converting a fractionaldecimal value to binary, we need to use a slightlydifferent approach. Instead of dividing by 2, werepeatedly multiply the decimal fraction by 2. If theresult is greater than or equal to 1, we add a 1 to ouranswer. If the result is less than 1, we add a 0 to ouranswer. The 0 fractional parts indicates the end of themultiplication.
-
7/29/2019 IB_Number Systems and Conversions
17/30
1. Decimal to Binary Conversion (Cont.)
Convert 0.37510 to binary.
Result
0.375 * 2 = 0.75 0 (Leftmost digit)
0.75 * 2 = 1.5 1
0.5 * 2 = 1.0 1 (Rightmost digit)
So, 0.37510 = 0.0112
So, a decimal number with fraction can be convertedto binary using the above methods.
25.37510 = 25 + 0.375 = 11001.0112
-
7/29/2019 IB_Number Systems and Conversions
18/30
2. Decimal to Octal Conversion
Repeated Division: repeatedly divide the decimal
number by 8, the base of the octal system. Division by8 will give a remainder of 0..7. Also, the result of thefinal division is always 0. Collecting the remaindersfrom the repeated divisions will give the octal number.
Example: convert 17710 to octal and binary:
177/8 = 22+ remainder of 1 1 (Least Significant Bit)
22/ 8 = 2 + remainder of 6 6
2 / 8 = 0 + remainder of 2 2 (Most Significant Bit)Result17710 = 2618
Convert to Binary = 0101100012
-
7/29/2019 IB_Number Systems and Conversions
19/30
3. Decimal to Hexadecimal Conversion
Repeated Division: repeatedly divide the decimal
number by 16, the base of the hexadecimal system.Division by 16 will give a remainder of 0..F(15). Also,the result of the final division is always 0. Collectingthe remainders from the repeated divisions will give
the hexadecimal number. Example: convert 37810 tohexadecimal and binary:
378/16 = 23+ remainder of 10A (Least Significant Bit)
23/ 16 = 1 + remainder of 7 7
1 / 16 = 0 + remainder of 1 1 (Most Significant Bit)
Result37810 = 17A8
Convert to Binary= 0001 0111 10102= 0000 0001 0111 1010
(16 bits)
-
7/29/2019 IB_Number Systems and Conversions
20/30
4. Binary to Decimal Conversion
Any binary number can be converted to its decimal
equivalent simply by summing together the weights of thevarious positions in the binary number which contain a 1.The method is find the weights (i.e., powers of 2) for eachbit position that contains a 1, and then to add them up.
1 1 0 1 12
(binary)
24+23+0+21+20 = 16+8+0+2+1
= 2710 (decimal)
1 0 1 1 0 1 0 12
(binary)
27+0+25+24+0+22+0+20 = 128+0+32+16+0+4+0+1
= 18110 (decimal)
-
7/29/2019 IB_Number Systems and Conversions
21/30
4. Binary to Decimal Conversion (Cont.)
Convert 1101012 to decimal number.
Binary
Weights
25 24 23 22 21 20
Weight
Value
32 16 8 4 2 1
BinaryNumber
1 1 0 1 0 1
Decimal
Value
32 16 0 4 0 1 Total
(53)10
-
7/29/2019 IB_Number Systems and Conversions
22/30
5. Binary to Octal Conversion
Each Octal digit is represented by three bits of binary
digit.
Partition each binary number into 3-bit group to theleft and right of the fractional point and then replacingeach 3-bit group by its equivalent octal number.
Octal Digit 0 1 2 3 4 5 6 7
Binary Equivalent 000 001 010 011 100 101 110 111
1001110102 = (100) (111) (010)2 = 4728
10011.10112
=(010) (011).(101)(100)2
= 23.548
-
7/29/2019 IB_Number Systems and Conversions
23/30
6. Binary to Hexadecimal
Each Hexadecimal digit is represented by four bits of
binary digit.
Partition each binary number into 4-bit group to the
left and right of the fractional point and then replacingeach 4-bit group by its equivalent hexadecimalnumber.
1011001011112 = (1011) (0010) (1111)2 = B2F16
11011.1012 = (0001)(1011).(1010)2 = 1B.A16
Hexadecimal Digit 0 1 2 3 4 5 6 7
Binary Equivalent 0000 0001 0010 0011 0100 0101 0110 0111
Hexadecimal Digit 8 9 A B C D E F
Binary Equivalent 1000 1001 1010 1011 1100 1101 1110 1111
-
7/29/2019 IB_Number Systems and Conversions
24/30
7. Octal to Decimal Conversion
To express the value of a given octal number as its
decimal equivalent we just need to sum the digits aftereach has been multiplied by its associated weight.
Convert (237.04)8 to decimal
Again, 24.68= 2 x (81
) + 4 x (80
) + 6 x (8-1
) = 20.7510
Weights 82 81 80 8-1 8-2
Weight
Value 64 8 1 0.125 0.015625
OctalNumber 2 3 7 0 4
Decimal
Value 128 24 7 0 0.0625 Total(159.0625)10
-
7/29/2019 IB_Number Systems and Conversions
25/30
8. Octal to Binary Conversion
Each Octal digit is represented by three bits of binary
digit.
For Octal to Binary conversion, convert each octal digit
to its corresponding binary digits.
Octal Digit 0 1 2 3 4 5 6 7
Binary Equivalent 000 001 010 011 100 101 110 111
4728 = (100) (111) (010)2 = 1001110102
53.68 = (101)(011).(110)2 = 101011.112
-
7/29/2019 IB_Number Systems and Conversions
26/30
9. Octal to Hexadecimal Conversion
Each Octal digit is represented by three bits of binary
digit.
1) Convert Octal to Binary first.2) Partition each binary number into 4-bit group to theleft and right of the fractional point and then replacingeach 4-bit group by its equivalent hexadecimal
number.
Octal Digit 0 1 2 3 4 5 6 7
Binary Equivalent 000 001 010 011 100 101 110 111
4728 = (100) (111) (010)2 = (0001) (0011) (1010)2 = 13A16
67.528 = (110)(111).(101)(010)2 =(0011)(0111).(1010)(1000)
2= 37.A8
16
-
7/29/2019 IB_Number Systems and Conversions
27/30
10. Hexadecimal to Decimal Conversion
To express the value of a given hexadecimal number
as its decimal equivalent, we just need to sum thedigits after each has been multiplied by its associatedweight.
The hexadecimal number is converted to decimal as
follow:2AF16 = 2 x (16
2) + 10 x (161) + 15 x (160)
= 2 x 256 + 10 x 16 + 15 x 1 = 512+160+15
= 68710
Weights 162 161 160 . 16-1 16-2
-
7/29/2019 IB_Number Systems and Conversions
28/30
11. Hexadecimal to Binary Conversion
Each Hexadecimal digit is represented byfourbits of
binary digit.
For Hexadecimal to Binary conversion, convert each
hexadecimal digit to its corresponding 4-bit binarydigit.
B2F16 = (1011) (0010) (1111)2 = 1011001011112
7.A3C16
= (0111).(1010)(0011)(1100) =111.10100011112
Hexadecimal Digit 0 1 2 3 4 5 6 7
Binary Equivalent 0000 0001 0010 0011 0100 0101 0110 0111
Hexadecimal Digit 8 9 A B C D E FBinary Equivalent 1000 1001 1010 1011 1100 1101 1110 1111
-
7/29/2019 IB_Number Systems and Conversions
29/30
12. Hexadecimal to Octal Conversion
Each Hexadecimal digit is represented by fourbits of
binary digit.
1) Convert Hexadecimal to Binary first.2) Partition each binary number into 3-bit group to the
left and right of the fractional point and then replacingeach 3-bit group by its equivalent hexadecimalnumber.
B2F16 = (1011) (0010) (1111)2 = (101) (100) (101) (111)2
= 54578
Hexadecimal Digit 0 1 2 3 4 5 6 7
Binary Equivalent 0000 0001 0010 0011 0100 0101 0110 0111
Hexadecimal Digit 8 9 A B C D E FBinary Equivalent 1000 1001 1010 1011 1100 1101 1110 1111
-
7/29/2019 IB_Number Systems and Conversions
30/30
THANK YOU ALL