Originally Posted by
MacNilly
Sounds like you want to convert binary to decimal. Remember that the mathematical value of a binary integer number is
b_n * 2^n + b_n-1 * 2^(n-1) + ... + b_0 * 2^0
where b_i is bit i
For the fractional part, you can extend this pattern using negative powers of the base. For example, .101 is equal to
1 * 2^(-1) + 0 * 2^(-2) + 1 * 2^(-3)
Basically, you need to look at each individual digit and its associated power of the representation base (2 for binary), and add the "place-value" of the digit to an accumulator sum initialized to 0.
BTW, its a bad idea to work with the internal representation (individual bits) of a "float," unless you are writing low level assembly library code that is allowed to make assumptions about the internal format the architecture uses for floats, like IEEE 754, etc. I'd suggest to stick with simple "float" values and use the mathematical definition to covert.