Python : Convert IEEE to IBM Floating Point

Python : Convert IEEE to IBM Floating Point

When creating code to read a SEG-Y file, I get the IEEE and IBM Floating Point format data. IBM floating point numbers are represented by one bit for the sign (S), 7 bits for the exponent, and 24 bits for the fraction.  The exponent is to the base 16 (not 2), and has a bias of 64.  Because of the base 16, the fraction may have up to three leading zeros.  In this manner, some of the exponential value may be assumed by the fraction, increasing its range, at the cost of some precision.  Normalization to the leading bit is not possible.   Floating point numbers have no complement (neither one’s nor two’s complement).  They are in sign-magnitude format (the sign being bit 31). You get the more information with the table below :

IBM 32-Bit Floating Point Format
S Exponent Fraction (Note: the most significant three bits
[23, 22, and 21] might all be zero).
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

With this information and searching in internet, I am create a Python to Convert IEEE to IBM Floating Point. You can copy this Python Convert IEEE to IBM Floating Point at below :

Save this Python to Convert IEEE to IBM Floating Point source code as ieee2ibm.py. Try to running this Python to Convert IEEE to IBM Floating Point with command :

This is a Python to Convert IEEE to IBM Floating Point source code, are you have other method to convert IEEE to IBM Floating Point ? Please share at here

Source :
http://nssdc.gsfc.nasa.gov/nssdc/formats/IBM_32-Bit.html

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.