yurib
yurib

Reputation: 8147

how to map float to 32 bit integer in python

From the AR Drone Developer's guide:

The number −0.8 is stored in memory as a 32- bit word whose value is BF 4CCCCD (16) , according to the IEEE-754 format. This 32-bit word can be considered as holding the 32-bit integer value −1085485875 (10).

Is there an "easy way" (built-in functions/existing modules) to do this in python ?

Upvotes: 0

Views: 1194

Answers (1)

P.Melch
P.Melch

Reputation: 8190

maybe not the best method, but it works.

import struct
s = struct.pack("f", -0.8)
i = struct.unpack("i", s)
print i

Upvotes: 6

Related Questions