On 26/02/2014 00:12, Oscar Benjamin wrote: > On 25 February 2014 11:08, Daniele Nicolodi <dani...@grinta.net> wrote: >> Hello, >> >> I'm dealing with an instrument that transfers numerical values through >> an RS232 port in a custom (?) floating point representation (56 bits, 4 >> bits exponent and 52 bits significand). >> >> Of course I need to convert this format to a standard IEEE 754 double to >> be able to do anything useful with it. I came up with this simple code: >> > > My first approach would be that if you have an int and you want it as > bits then you can use the bin() function e.g.: >>>> bin(1234) > '0b10011010010' > > You can then slice and reconstruct as ints with >>>> int('0b101', 2) > 5
How would that be helpful? I believe it is much more computationally expensive than relying on simple integer math, especially in the optics of cythonization. > Similarly my first port of call for simplicity would be to just do > float(Fraction(mantissa, 2**exponent)). It doesn't really lend itself > to cythonisation but it should be accurate and easy enough to > understand. "simpler" in my original email has to be read as involving less operations and thus more efficient, not simpler to understand, indeed it is already a simple implementation of the definition. What I would like to know is if there are some smart shortcuts to make the computation more efficient. Cheers, Daniele _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion