interpret 4 byte as 32-bit float (IEEE-754)

Scott David Daniels Scott.Daniels at Acm.Org
Sat Jan 15 16:47:55 EST 2005


G.Franzkowiak wrote:
> Scott David Daniels schrieb:
>> If you really want to do this kind of byte fiddling:
>>     http://members.dsl-only.net/~daniels/block.html
>> Then:
>>     from block import Block, View
>>     b = Block(4) # enough space for one float (more is fine)
>>     iv = View('i', b) # getting to it as an integer
>>     fv = View('f', b) # same memory as floating point
>>     iv[0] = 0x3F8CCCCD # Here is a sample just using the integer
>>     print fv[0]
>> On an Intel/Amd/Generic "PC" machine, you should get 1.1
> 
> That's good :-))
> I'm missing the makefile ;-)
> I'm using the other world... right
There's a lot more than one other world.  distlib is your friend.

There is no makefile.  If you are not on a windows box,
get the source, extract the files from the zip, and run:

     python setup.py install

-Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list