Newbie lost(new info)
Howard Lightstone
howard at eegsoftware.com
Fri Feb 27 23:48:23 EST 2004
Angelo Secchi <secchi at sssup.it> wrote in
news:mailman.150.1077786326.8594.python-list at python.org:
>
> John and Anthon thanks for your help.
> If I did it correctly this is the outcome of the code you asked me to
> try:
>
>>from binascii import hexlify
>>inf = file('foo','rb')
>>data = inf.read(1970) # 1970 is the exact length of the line
>>for i in range(4):
>> index = i * 32
>> print hexlify(data[index: index+32])
>
>
> 3131313131313131312030313032323230313033343130323238353332303031
> 3220202020203032323835333230303132303030303031303030303030314338
> 3930303030303120203939333531302030313130303030312020313220313335
> 313030313032323230313033343133343146ee3bb40000000000000000465de3
>
>
>
>>from binascii import hexlify
>>inf = file('foo','rb')
>>data = inf.read(1970)
>>for i in range(223):
>> index = i * 4 + 113
>> print hexlify(data[index: index + 4])
>
>
> 46ee3bb4 (I know that this should be 15612852)
> 00000000 (I know that this should be 0)
> 00000000 (I know that this should be 0)
> 465de39a (I know that this should be 6153114)
> 00000000 (I know that this should be 0)
> 00000000 (I know that this should be 0)
> ...
I seem to recall that the format is
sCCCCCCC MMMMMMMM MMMMMMMM MMMMMMMM
The CCCCCCC exponent is biased by 64 and is HEX (16**(CCCCCCC-64)).
I recall significance issues on Gould machines because the normalization
was only to the nibble so there might be 2 or 3 0-bits in the mantissa.
41100000 was 1.0
My sample code:
import struct
dividend=float(16**6)
def fromhex370(invalue):
"convert 4 char binary string 370-formatted floating point float value"
if invalue == 0:
return 0.0
istic,a,b,c=struct.unpack('>BBBB',invalue)
if istic >= 128:
sign= -1.0
istic = istic - 128
else:
sign = 1.0
mant= float(a<<16) + float(b<<8) +float(c)
return sign* 16**(istic-64)*(mant/dividend)
Of course, no optimation was even thought of ......
I believe the long floating point format just added 4 more bytes of
significance to the end of the 4 bytes I mentioned above.
HTH
More information about the Python-list
mailing list