tmp-ibm | index /Users/schwehr/projects/xcore/src/segy-py/tmp-ibm.py |
Angelo Secchi
secchi@sssup.it
http://193.205.80.238/~angelo/ibm.html
IBM System/370 mainframes and standard PC based on Intel
microprocessors use different internal storage for floating points
numbers. Here a brief description together with other sources of
informations.
IBM/370 Floating point format. The single precision floating point is
represented by 32 bits. The first is the sign bit. From bit 1 to 7 you
find the exponent represented as a power of 16 in 'excess 64' notation
(giving a value range of 16**-65 <= M <= 16**63).From bit 8 to 31 is
the base-16 (hex) fraction left-shifted (normalized) 4 bits at a time
to where the first four bits (nibble) contain a numeric value on the
right of an imaginary radix-point (with the exponent raised
appropriately during the shift). For details see: IBM System/370 Model
168, Theory of Operation/Diagrams Manual, Volume 2, I-unit, Form
SY22-6932-0, IBM Corporation, Poughkeepsie, New York, April 1973.
IEEE-754 Floating point format.
The single precision floating point is represented by 32 bits. The first is the sign bit. From bit 1 to 7 you find the exponent represented as a power of 2 in 'excess 127' notation. From bit 8 to bit 31 you find the base-2 fraction left-shifted to where the first binary '1' is on the left of an imaginary binary-point (with the exponent raised appropriately during the shift) giving a precision of 24 bits stored in 23 bits. For details see: IEEE-754 Floating point format
Python Functions
Python is a simple language that makes available also to 'not programmer' (like I am) a powerful tool without investing huge amount of time (www.python.org). The material provided in this page comes from the Pyhton community and in particular from Howard Lightstone and Anton Vredegoor. Please notice that these two functions have been tested several times but only by myself.
Suppose you have a binary file, called data, created on an IBM/370 System with 223 equal fields where a single precision (4 bytes) float is stored and you want to convert it to IEEE-754 standard. Here the first sample code that uses the Python 'struct' module.
import struct
Modules | ||||||
|
Functions | ||
|
Data | ||
dividend = 16777216.0 |