how can I convert a binary float to a base 10 float and vice versa?
Question: I have a binary float like '10.1' and want to convert it to a decimal float.
Then I want to do some operations on it and convert it back to a binary float.
Are there builtins in python 2 to do this? If not, what is the shortest (in
bytes) way to do this?


Answer: There's no built-in way to do this for binary (though there is from
[hexadecimal](https://docs.python.org/2/library/stdtypes.html#float.fromhex)).
The easiest way would be to strip out the `.`, parse as an integer, and scale
appropriately:

    
    
    import math
    x = "10.1"
    p = len(x) - x.index(".") - 1
    i = int(x.replace(".",""),2)
    math.ldexp(i,-p)
    

This assumes your string consists of nothing but `0`s, `1`s and a single `.`
(i.e. no whitespace or exponent).

