Newbie: How To Convert A Float Into Two Sixteen Bit Integers.....?

Ignacio Vazquez-Abrams ignacio at openservices.net
Thu Sep 13 16:37:20 EDT 2001


On Thu, 13 Sep 2001, John Branthoover wrote:

>     Can any tell me how I can take a single precision floating point number
> and convert it into two sixteen bit integers using Python?  I need to store
> some floating point numbers in a eight bit wide EEPROM.

If you need it in IEEE 756 format, then you can use the struct module with the
'f' specifier. If you need it in 16.16 format, then you need to mod it with
65536 and floor it for the first 16, multiply it by 65536, mod it, then floor
it for the second 16, then use 'hh' instead.

-- 
Ignacio Vazquez-Abrams  <ignacio at openservices.net>





More information about the Python-list mailing list