I am looking for the Python equivalent of Java's Float.floatToBits
.
I found this Python: obtain & manipulate (as integers) bit patterns of floats but does anyone know of a less complicated way?
I am looking for the Python equivalent of Java's Float.floatToBits
.
I found this Python: obtain & manipulate (as integers) bit patterns of floats but does anyone know of a less complicated way?
Here is the 64-bit, little endian representation of a python float1 just to add to the discussion:
References:
struct.pack
endianness and byte size format specifiersbinascii.hexlify
[1] for example I needed this specifically for interoperability with .NET's
BitConverter
on intel (ie little endian)The answer that Alex Martelli gives in that question is really pretty simple -- you can reduce it to:
Once you have it as an integer, you can perform any other manipulations you need to.
You can reverse the order of operations to round-trip: