Base Conversion: binary numbers to decimal ones, and decimal numbers to binary ones
MatrixLab Examples
To see an online base converter, see: http://matrixlab-examples.com/base-conversion.html
I'm gonna show you how to convert a binary number to a decimal one, and a decimal number to a binary base.
Any digit in a decimal number has a different weight. The weight is the power of its position in the number.
The same concept can be applied to numbers in any other base. We can obtain the equivalent number in decimal base just by adding every digit multiplied by the base to the corresponding power.
For numbers less than the unit, we have to consider negative powers, just as considered in numbers of base 10.
To convert decimal numbers to binary ones, we are going to iterate divisions by 2. We are going to take the remainder for the result, and we are going to take the quotient for another division. We are going to divide by the base until our quotient becomes less than the base. We have to include our last quotient and our last reminder for the final result in base 2.
To convert decimal numbers that happen to be less than the unit, we are going to iterate multiplications by the base (in this case it's 2). The integer part of each result goes to our conversion and the fraction goes to another multiplication. The final conversion is an approximation only, even though we could make more multiplications to have better accuracy.
Thank you for watching.
5473335 Bytes