Number Base Conversion is the process of converting a number from one base to another.
In this post, we will be converting from base 2 to base 10, and vice versa.
Base 2 has only two digits, which are 0 and 1.
On the other hand, Base 10 has 10 digits, namely; 0,1,2,3,4,5,6,7,8,9.
Conversion From Base 2 to Base 10
To convert from base 2 to base 10, you must follow the following steps:
- Write the number you want to convert from base 2 to base 10.
- Starting from the rightmost digit and starting from zero, assign digits and raise 2 to the power of the digits.
- Multiply each digit by its corresponding value.
- Add up the product together.
To put this into practice, we take some examples.
Example 1
Convert \(10111_2\) to decimal.
Solution:
10111 has five digits. So the righter most digit (fifth digit) will be multiplied by 2 to the power of 0. The second right to the right (fourth digit) will be multiplied by 2 to the power of 1, and so on.
\(1×2^4+0×2^3+1×2^2+1×2^1+1×2^0\)
Let’s now add the result
\(16+0+4+2+1=23\)
Example 2
Convert \(1000011_2\) to base 10.
Solution:
1000011 has 7 digits. The seventh digit will be multiplied by 2 raised to the power of 0, the sixth digit will be multiplied by 2 raised to the power of 1, the fifth digit will be multiplied by 2 raised to the power of 2, and so on.
\(\small{1×2^6+0×2^5+0×2^4+0×2^3+0×2^2+1×2^1+1×2^0}\)
We can then add the result
\(64+0+0+0+0+2+1=67\)
Conversion from Base 10 to Base 2
To convert a digit from base 10 to base 2, you must follow the following steps:
- Write the digit down
- Divide the digit by 2
- Write the remainder after the division. The remainder will be either 0 or 1.
- Divide the result of the division by 2.
- Repeat steps 3 and 4 until the division results in 0.
- The sequence of remainders written down in reverse order represents the digit in base 2.
Example 3
Convert \(58_{10}\) to base 2.
Solution:
We will continue to divide 58 by 2 until we get to 2.
58/2=29 R 0
29/2=14 R 1
14/2= 7 R 0
7/2 = 3 R 1
3/2 = 1 R 1
1/2 = 0 R 1
So, reading the remainders from the whole from upward, \(58_{10}=111010_2\)
Example 4
Convert 27 from decimal to binary.
Solution:
Now, let’s divide the digit by 2 until we get a quotient that is zero.
27/2=13 R 1
13/2= 6 R 1
6/2 = 3 R 0
3/2 = 1 R 1
1/2 = 0 R 1
So, 27 in decimal is 11011 in binary.
Conversion of Floating-point Numbers From Base 2 to Base 10
Some base 2 numbers usually have a decimal number. These are called floating-point numbers.
Examples of floating point numbers are 101.0111.
To convert a floating-point base 2 digits to base 10, you should follow these steps:
- Divide the digit into the integer part and the fractional part.
- You can convert the integer part into decimals using the usual way of converting base 2 to base 10.
- Now, To convert the numbers after the decimal point to decimal, you should follow these steps:
- Starting from the leftmost digit and starting from -1, assign digits of -1, -2,-3 and so on to the digits after the decimal point.
- Multiply each digit of the fractional part by the corresponding power of 2.
- Add the results.
- Add the result of 2 and 3 together. The final result is the digit in base 10.
Example 5
Convert \(111.101_2\) to base 10.
Solution:
First, we need to separate the digits into integer and fractional parts. 111 is the integer part while 0.101 is the fractional part.
Let’s now convert using the normal way of converting:
\(1 \times 2^2+ 1 \times 2^1 + 1 \times 2^0=7\)
Now, we assign power to raise to the power of 2.
\(1 \times 2^{-1} +0 \times 2^{-2} + 1 \times 2^{-3}\)
We can then add the numbers
\(0.5+0+0.125=0.625\)
Adding the integral part and fractional part
\(7+0.625=7.625\)
Conversion of Floating-point numbers from Base 10 to Base 2
The following steps can be used to convert floating numbers from decimal to binary.
- Separate the numbers into integer and fractional parts.
- Converts the integer as you would normally convert decimal numbers to binary.
- Now, for the decimal part, follow the steps:
- Multiply the fractional part by 2 and keep track of the integer part of the result.
- Continue the above step until you get a fractional part of 0 or after 5 significant figures.
Example 6
Convert \(10.625_{10}\) to a number in base 2
Solution:
10 is the integer part while 0.625 is the fractional part. Now, let’s convert the way we usually cover base 10 to base 2.
10/2=5 R 0
5 /2= 2 R 1
2/2 = 1 R 0
1/2 = 0 R 1
So, \(10_{10}=1010_2\)
Now, let’s convert the fractional part 0.625 to base 2
0.625 × 2=1.250
0.250 × 2=0.5
0.5 × 2 =1.0
Reading the integer part, \(0.625_{10}=0.101_2\)
Now, \(10.625_{10}\) in base 2 will be the sum of 10 and 0.625 in base 2
\(10.625_{10}=1010_2+0.101_2=1010.101_2\)