1

What is the format to convert a decimal to ieee754?

I can use

x = ibm2float32(numpy.uint32(0xc1180000))
print(x)

but I want to do the reverse.

Mark Dickinson
  • 29,088
  • 9
  • 83
  • 120
  • 1
    Do you definitely want output matching the IBM hexadecimal format? If so, can I ask what the use-case is? (I've found lots of use-cases for being able to turn historical data in an esoteric format into something usable on modern machines, but few use-cases for going in the other direction.) Your first line says that you want to convert to IEEE 754, but that would be quite a different task from converting to IBM hex floating-point. So I'm a bit confused. – Mark Dickinson Mar 16 '23 at 18:01
  • 1
    For a bit more context: [ibm2ieee](https://github.com/enthought/ibm2ieee) was written with a fairly specific application in mind: that of reading seismic data from old [SEG-Y](https://en.wikipedia.org/wiki/SEG-Y) files. If you're trying to create such SEG-Y files (e.g., for testing purposes), that would be one possible application. – Mark Dickinson Mar 16 '23 at 18:06
  • https://stackoverflow.com/questions/7125890/python-unpack-ibm-32-bit-float-point might help (ieee exp is 8 bits, ieee mantissa is 23 bits w/ an assumed 1; ibm exp is 7 bits, ibm mantissa is 24 bits w/ no assumed 1) – Andrew Mar 18 '23 at 02:55

0 Answers0