If you intend to perform these conversions while working under Windows, you can quickly download and install mbf2ieee.exe and call it CVS, which is suggested by the result Mbf2ieee.dll(for example, via [ctypes] [2]).
Python, ( , MBF ), ( Python C- ):
def mbf2ieee(mbf_4bytestring):
msbin = struct.unpack('4B', mbf_4bytestring)
if msbin[3] == 0: return 0.0
ieee = [0] * 4
sign = msbin[2] & 0x80
ieee_exp = msbin[3] - 2
ieee[3] = sign | (ieee_exp >> 1)
ieee[2] = (ieee_exp << 7) | (msbin[2] & 0x7f)
ieee[:2] = msbin[:2]
return struct.unpack('f', ieee)[0]
, ?
: , :
def float2mbf4byte(f):
ieee = struct.pack('f', f)
msbin = [0] * 4
sign = ieee[3] & 0x80
msbin_exp = (ieee[3] << 1) | (ieee[2] >> 7)
if msbin_exp == 0xfe: raise OverflowError
msbin_exp += 2
msbin[3] = msbin_exp
msbin[2] = sign | (ieee[2] & 0x7f)
msbin[:2] = ieee[:2]
return msbin