Re: how to convert 4 bytes into a float ?
From: Fredrik Lundh (fredrik_at_pythonware.com)
Date: 02/08/05
- Next message: Jean de Largentaye: "Re: Choosing the right parser for parsing C headers"
- Previous message: Steve Holden: "Re: def __init__ question in a class definition"
- In reply to: Alex Martelli: "Re: how to convert 4 bytes into a float ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: python-list@python.org Date: Tue, 8 Feb 2005 13:23:11 +0100
Alex Martelli wrote:
> I don't recall for sure (even though I did my thesis on a Vax, 25 years
> ago!) but I think you _might_ be lucky -- VAX used the binary format
> that became the IEEE standard, if I recall correctly.
iirc, you have to swap bytes around. the code on this page might
be helpful:
http://www.octave.org/octave-lists/archive/octave-sources.2004/msg00033.html
> The problem would be there if you had, say, floats in old IBM 360/370
> formats, or Cray's original formats, or the like...
here's a IBM 360 converter (at least that's what I think it is; the code is taken
from a PIL format converter for a format that uses "IBM floats"):
def ibm_f32s(c):
a = ord(c[0]) & 127
b = ord(c[3]) + (ord(c[2])<<8) + (ord(c[1])<<16)
v = pow(2.0, -24) * b * pow(16.0, a-64)
if ord(c[0]) > 127:
return -v
return v
many floating point formats are trivial variations on this theme.
</F>
- Next message: Jean de Largentaye: "Re: Choosing the right parser for parsing C headers"
- Previous message: Steve Holden: "Re: def __init__ question in a class definition"
- In reply to: Alex Martelli: "Re: how to convert 4 bytes into a float ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|