IB - Number Systems and Conversions
IB - Number Systems and Conversions
IB - Number Systems and Conversions
Abu Ahmed Ferdaus Assistant Professor Department of Computer Science & Engineering Dhaka University
1. 2.
3.
4.
Many number systems are in use in digital technology. The most common are: Decimal number system base 10 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) Binary number system base 2 (0, 1) Octal number system base 8 (0, 1, 2, 3, 4, 5, 6, 7) 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.
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 can express any quantity. The decimal system, also called the base-10 system because it has 10 digits.
102
101 100
10-1 10-2
Decimal Numbers
it is three thousands plus five hundreds plus four tens plus six ones.
329
102 101 100
3x100 + 2x10 + 9x1 = 329
Binary System
In the binary system, there are only two symbols or possible digit values, 0 and 1. This base-2 system can be used to represent any quantity that can be represented in decimal or other number system.
22 21 20 =4 =2 =1 . Binary point
2-1
2-2
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
most significant
101
22 21
least significant
20
Fractional Values
In Decimal
0.329
10-1 10-2 10-3
3x0.1 + 2x0.01 + 9x0.001 = 0.329
In Binary
0.011
2-1 2-2 2-3
0x0.5 + 1x0.25 + 1x0.125 = 0.375
82
81 80
8-1
8-2
Octal Numbers
327
82 81 80
3x64 + 2x8 + 7x1 = 215
162
161 160
16-1
16-2
Hexadecimal Numbers
27B
162 161 160
2x256 + 7x16 + 11x1 = 635
Number Conversion
Number Conversion can be viewed as:
Binary
Decimal
Octal
Hexadecimal
Repeated Division: repeatedly divide the decimal number by 2, the base of the binary system. Division by 2 will either give a remainder of 1 (dividing an odd number) or no remainder (dividing an even number). Collecting the remainders from the repeated divisions will give the binary answer. Example: convert 2510 to binary.
25/ 2 = 12+ remainder of 1 1 (Least Significant Bit)
12/ 2
6/2 3/2 1/2 Result
= 6 + remainder of 0
= 3 + remainder of 0 = 1 + remainder of 1 = 0 + remainder of 1 2510 =
0
0 1 1 (Most Significant Bit) 1 1 0 0 12
Reading from bottom to top, the final answer is 11001. Remember that the first division gives us the least significant digit of our answer, and the final division gives us the most significant digit of our answer. Also, the result of the final division is always 0. Converting Fraction: When converting a fractional decimal value to binary, we need to use a slightly different approach. Instead of dividing by 2, we repeatedly multiply the decimal fraction by 2. If the result is greater than or equal to 1, we add a 1 to our answer. If the result is less than 1, we add a 0 to our answer. The 0 fractional parts indicates the end of the multiplication.
So, a decimal number with fraction can be converted to binary using the above methods. 25.37510 = 25 + 0.375 = 11001.0112
Repeated Division: repeatedly divide the decimal number by 8, the base of the octal system. Division by 8 will give a remainder of 0..7. Also, the result of the final division is always 0. Collecting the remainders from 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) Result 17710 = 2618 Convert to Binary = 0101100012
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. Collecting the remainders from the repeated divisions will give the hexadecimal number. Example: convert 37810 to hexadecimal and binary:
378/16 = 23+ remainder of 10 23/ 16 = 1 + remainder of 7 1 / 16 = 0 + remainder of 1 Result 37810 = Convert to Binary A (Least Significant Bit) 7 1 (Most Significant Bit) 17A8 = 0001 0111 10102 = 0000 0001 0111 1010 (16 bits)
= 18110 (decimal)
32
16
32
16
Total (53)10
Octal Digit 0 1 2 3 4 5 6 7 Binary Equivalent 000 001 010 011 100 101 110 111
Partition each binary number into 3-bit group to the left and right of the fractional point and then replacing each 3-bit group by its equivalent octal number. 1001110102 = (100) (111) (010)2 = 4728 10011.10112 =(010) (011).(101)(100)2 = 23.548
6. Binary to Hexadecimal
Partition each binary number into 4-bit group to the left and right of the fractional point and then replacing each 4-bit group by its equivalent hexadecimal number. 1011001011112 = (1011) (0010) (1111)2 = B2F16 11011.1012 = (0001)(1011).(1010)2 = 1B.A16
To express the value of a given octal number as its decimal equivalent we just need to sum the digits after each has been multiplied by its associated weight.
64
0.125
0.015625
128
24
0.0625
Total (159.0625)10
Octal Digit 0 1 2 3 4 5 6 7 Binary Equivalent 000 001 010 011 100 101 110 111
For Octal to Binary conversion, convert each octal digit to its corresponding binary digits. 4728 = (100) (111) (010)2 = 1001110102 53.68 = (101)(011).(110)2 = 101011.112
1) Convert Octal to Binary first. 2) Partition each binary number into 4-bit group to the left and right of the fractional point and then replacing each 4-bit group by its equivalent hexadecimal number. 4728 = (100) (111) (010)2 = (0001) (0011) (1010)2 = 13A16
To express the value of a given hexadecimal number as its decimal equivalent, we just need to sum the digits after each has been multiplied by its associated weight.
Weights 162 161 160 . 16-1 16-2
The hexadecimal number is converted to decimal as follow: 2AF16 = 2 x (162) + 10 x (161) + 15 x (160) = 2 x 256 + 10 x 16 + 15 x 1 = 512+160+15 = 68710
For Hexadecimal to Binary conversion, convert each hexadecimal digit to its corresponding 4-bit 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 replacing each 3-bit group by its equivalent hexadecimal number.