decoding floats
Nico Hartmann
nico.hartmann at daimlerchrysler.com
Thu Nov 29 01:53:44 EST 2001
> > Hi there,
> >
> > I look for a way to decode and encode float values into byte arrays.
>
> >>> import array
> >>> a = array.array('f')
> >>> a.append(42.42)
> >>> a.tostring()
> '\x14\xae)B'
>
> Something like this?
Yes, that would do. I figured out using the stuct.pack from struct package
also works fine:
import struct
bytes = struct.pack("d", 34.34)
Regards,
nico
More information about the Python-list
mailing list