[SPAM-Bayes] - Re: Converting IBM Floats..Help.. - BayesianFilter detected spam

Ian Sparks Ian.Sparks at etrials.com
Fri Mar 26 17:49:01 EST 2004


>>
You might find my weird little bits module helpful to take your floating
point values in python apart in order to send them around.

     http://members.dsl-only.net/~daniels/bits.html
<<

Could you demonstrate this?

Lets say I have my 8 bytes representing an IBM360 (BigEndian) double number :

bytes =  'B\x9b\x00\x00\x00\x00\x00\x00' #155

and I know the format of the number is :

SEEEEEEEMMMM ......... MMMM

Sign bit, 7 bit exponent, 56 bit fraction. Exponent is
excess 64. The fraction is multiplied by a power of 16 of
the actual exponent. Normalized floating point numbers are
represented with the radix point immediately to the left of
the high order hex fraction digit.

How would I decode this to my IEEE number? This isn't it but would it look something like :

import struct
import bits

bytes =  'B\x9b\x00\x00\x00\x00\x00\x00' #155
l = struct.unpack('>Q',bytes)[0]

sign = bits.bit(l,63)
exponent = bits.extract(l,56,62) - 64
mantissa = bits.extract(l,0,55)

print [1,-1][sign] * (16**exponent) * mantissa 

?








-----Original Message-----
From: Scott David Daniels [mailto:Scott.Daniels at Acm.Org]
Sent: Friday, March 26, 2004 3:39 PM
To: python-list at python.org
Subject: Re: [SPAM-Bayes] - Re: Converting IBM Floats..Help.. -
BayesianFilter detected spam


Jeff Epler wrote:
> Here's one page I found with an explanation of how more standard
> floating-point numbers are stored:
>     http://ccrma-www.stanford.edu/~jos/mdft/Floating_Point_Numbers.html
> The most important difference between the IEEE formats and the IBM
> format is that the radix is 16 instead of 2.  I think there's also a
> terminlogy error--the page says that the significand (mantissa) is
> stored in "two's compliment binary", but this isn't true.  It's
> unsigned.  The sign is stored separately.
Actually, a common trick is to use "two's complement binary" on the 
entire word, not simply the mantissa.  Then the same hardware can be
used to negate integer and floating values.  The way you take apart
negative numbers is (1) record the sign, and (2) take the absolute value 
of the whole thing (3) breaking exponent and mantissa out.

You might find my weird little bits module helpful to take your floating
point values in python apart in order to send them around.

     http://members.dsl-only.net/~daniels/bits.html

-- 
-Scott David Daniels
Scott.Daniels at Acm.Org
-- 
http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list