retrieve bitwise float representation

Ulrich Eckhardt eckhardt at satorlaser.com
Wed Jun 10 09:41:00 EDT 2009


Hi!

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 this:

  tmp = struct.pack("=f", f)
  (i,) = struct.unpack("=L", tmp)

IOW, I pack and unpack the float using the struct module, which works.


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.

Thank you!

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932




More information about the Python-list mailing list