1.2.2) Conversion from any number system to another: base-n to decimal
In lesson 2, you know that there are many number systems, and I told you that you can convert from any number system to another, so from here, we will learn how to convert from any number system to another.
1.2.2.1) Conversion from any base-n number system to the decimal number system:
We will simply apply the general algorithm.
Write the weights above the digits (i.e., \(n^i\) ), multiply each digit by its weight, and then take the summation of the products.
a) conversion from binary system to the decimal system
Example 5:
Convert (1011.11)2 to the decimal number system?
You have 2 ways to solve this:
First method:
(1011)_2=(1\times2^3\ )+(0\times2^2\ )+(1\times2^1\ )+(1\times2^0\ )+(1\times2^{-1}\ )+(1\times2^{-2}\ )
=8+0+2+1+1/2+1/4=(11.75)_{10}
As you can see, we multiply each digit by the weight associated with the digit’s position. The weight is written as the base of the binary number system raised to the index of the digit.
Second method: is to use the table you have seen before.
× | 8 | 4 | 2 | 1 | ½ | ¼ | ||
1 | 0 | 1 | 1 | . | 1 | 1 | Sum (11.75)10 | |
= | 8 | 0 | 2 | 1 | ½ | ¼ |
Notice that in the conversion from a binary number system to the decimal number system, we only get the summation of the weights with the positions occupied by the ones.
Also, notice that in the integer part, you multiply each weight by 2 as we go from right to left, while in the fractional part, we divide by 2 as we go from left to right.
Of course, the second solution is easier.
b) Conversion from Ternary system to the decimal system
Example 6:
Convert (201.2)3 to the decimal number system.
Notice that the 3 is written as a subscript, which means that the 201.2 is a number in the ternary number system, which has only 3 digits: 0 to 2.
First method:
(201.2)_3=(2×3^2)+(0×3^1)+1×(3^0)+(2×3^{-1})=18+0 +1 +0.6666=(19.66666)_{10}
Second method:
× | 9 | 3 | 1 | \(\frac{1}{3}\) | ||
2 | 0 | 1 | . | 2 | Sum (19 \(\frac{2}{3}\))10 | |
= | 18 | 0 | 1 | \(\frac{2}{3}\) |
You will notice the following:
- In any number system, the weight of the rightmost digit of the integer part always equals 1 because the index of the first digit is always 0 and \(n^0 = 1\).
- Starting from the ternary number system, you can’t simply add the weights without multiplying them by their digits. We can do this in the binary number system because the biggest digit in the binary system is 1, and multiplying any number by 1 is the number itself.
c) Conversion from Octal system to the decimal system
Example 7:
Convert (127.64)8 to the decimal number system.
First method:
(127.64)_8=(1\times8^2\ )+(2\times8^1\ )+(7\times8^0\ )+(6\times8^{-1}\ )+(4\times8^{-2}\ )
=64+16+7+0.75+0.0625=(87.8125)_{10}
Second method:
× | 64 | 8 | 1 | \(\frac{1}{8}\) | \(\frac{1}{64}\) | ||
1 | 2 | 7 | . | 6 | 4 | Sum (87 \(\frac{13}{16}\))10 | |
= | 64 | 16 | 7 | \(\frac{3}{4}\) | \(\frac{1}{16}\) |
d) Conversion from Hexadecimal system to the decimal system
Example 8:
Convert (1CF.A3)16 to the decimal number system.
Do not forget that
A = 10, B = 11, C = 12, D = 13, E = 14, F = 15
First method:
(1CF.A3)_16=(1\times16^2\ )+(12\times16^1\ )+(15\times16^0\ )+(10\times16^{-1}\ )+(3\times16^{-2}\ )
=256+192+15+0.625+0.01171875=(463.63671875)_{10}
Second method:
× | 256 | 16 | 1 | \(\frac{1}{16}\) | \(\frac{1}{256}\) | ||
1 | C | F | . | A | 3 | Sum (463 \(\frac{163}{256}\))10 | |
= | 256 | 192 | 15 | \(\frac{10}{16}\) | \(\frac{3}{256}\) |