retrieve bitwise float representation

Scott David Daniels Scott.Daniels at Acm.Org
Wed Jun 10 11:24:47 EDT 2009


Ulrich Eckhardt wrote:
> I need to pack a floating point value into a vector of 32-bit unsigned
> values in IEEE format. Further, I maintain a CRC32 checksum for integrity
> checking. For the latter, I actually need the float as integral value.
> 
> What I currently do is ... pack and unpack the float using struct....
> What I'm wondering is whether there are any better or alternative ways to
> achieve this, the overhead now seems enormous and unnecessary to me here.

If you have just a few values, ignore the overhead.  Do you really need
more cycles for minesweeper?  If you have a vector, look into writing
from the array directly -- using cStringIO if you need to get to the
result within Python, rather than as an I/O format.

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list