Re: how to convert 4 bytes into a float ?

From: Fredrik Lundh (fredrik_at_pythonware.com)
Date: 02/08/05


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>



Relevant Pages

  • Buslink USB floppy (was: Re: Yee-Haa!! 5.25-inch USB floppy!)
    ... Buslink USB floppy drives: ... TRS-80 Model I/III or Tandy Model 4 formats, ... all IBM PC DD DOS 5.25" formats incl. ... but I'm ASSUMING that a Buslink 3.5" assembly ...
    (comp.os.cpm)
  • Re: Yee-Haa!! 5.25-inch USB floppy!
    ... TRS-80 Model I/III or Tandy Model 4 formats, ... and a few manually overridden XP command prompt format commands: ... all IBM PC DD DOS 5.25" formats incl. ... I tried to find the Buslink for $15 but never could. ...
    (comp.os.cpm)
  • Re: WCBT (Work Control Block Table) layout doucment?
    ... Try this overview from IBM ... It gives a great overview and explains about QWCBT00-30 formats and ... what you can see from OS400 (DSPJOBTBL) and from DST which sounds more ...
    (comp.sys.ibm.as400.misc)
  • Re: MSForms.DataObject Misbehaving
    ... Here's one way to swap the contents and formatting of two ... Dim R1 As Range ... _swap_ the values and formats. ... X when pasting Range Y into it. ...
    (microsoft.public.excel.programming)
  • MSForms.DataObject Misbehaving
    ... I am trying to swap the contents and formats of two equally sized ... End Sub ... Any suggestions how to swap two ranges while keeping the ...
    (microsoft.public.excel.programming)