Converting IBM Floats..Help..

Ian Sparks Ian.Sparks at etrials.com
Thu Mar 25 10:40:41 EST 2004


Hi,

I'm trying to read from a file which contains numbers encoded in IBM360 (Big-Endian) Floating point format. The IBM stores its numbers in the following format :

*
* IBM format:
* 6       5                 0
* 3       1                 0
*
* 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.

I know what's in this file so :

 data = list(file.read(8))
 print data
 
 155 = ['B', '\x9b', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00'] 
  77 = ['B', 'M', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00']
   1 = ['A', '\x10', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00']
   0 = ['\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00']

This is where my computer science breaks down. I'm pretty sure I'm going to need the struct module and some bitwise operations but I'm stuck. Anyone have some advice for me? 

Thank you.





More information about the Python-list mailing list