Does any one recognize this binary data storage format

G

geskerrett

Thanks so much for this. It is exactly what I was looking for.

If I am simply reading the bytes from disk, would I still need to
convert the these values HEX characters first with Hexlify, or is there
a more direct route ?
ie. convert them to the double float directly from the byte values ?
 
B

Bengt Richter

Thanks so much for this. It is exactly what I was looking for.

If I am simply reading the bytes from disk, would I still need to
convert the these values HEX characters first with Hexlify, or is there
a more direct route ?
ie. convert them to the double float directly from the byte values ?
Yes. Use struct.unpack ;-)

BTW, my second post was doing ''.join(chr(int(h[i:i+2],16)) for i in xrange(0,16,2))
to undo the hexlify you had done (I'd forgotten that there's a binascii.unhexlify ;-)

Regards,
Bengt Richter
 
G

Grant Edwards

That would just be sick. I can't imagine anybody on an 8-bit
CPU using FP for a phone number.
... "convert little-endian hex of ieee double binary to double"
... assert len(dhex)==16, (
... "hex of double in binary must be 8 bytes (hex pairs in little-endian order")
... dhex = ''.join(reversed([dhex[i:i+2] for i in xrange(0,16,2)]))
... m = int(dhex, 16)
... x = ((m>>52)&0x7ff) - 0x3ff - 52
... s = (m>>63)&0x1
... f = (m & ((1<<52)-1))|((m and 1 or 0)<<52)
... return (1.0,-1.0)*f*2.0**x
...7777777777.0

;-)


Damn.

I still say that's just plain sick.
 
G

Grant Edwards

Well done, Scott & Bengt!!
I've just verified that this works with all 12 corrected examples posted
by the OP.

Grant, MS-DOS implies 16 bits at least;

You're right. For some reason I was thinking you had said CP/M.
and yes there was an FPU (the 8087).

I never met an MS-DOS box that had an 8087 (though I did write
firmware for an 8086+8087 fire-control computer once upon a
time).
And yes there are a lot of sick people who store things as
numbers (whether integer or FP) when the only arithmetic
operations that can be applied to them stuff them up mightily
(like losing leading zeroes off post-codes, having NEGATIVE
tax file numbers, etc) and it's still happening on the best
OSes and 64-bit CPUS. Welcome to the real world :)

I've been in the real world for a long time, and the dumb
things people (including myself) do still surprise me.
 
C

Calvin Spealman

You're right. For some reason I was thinking you had said CP/M.


I never met an MS-DOS box that had an 8087 (though I did write
firmware for an 8086+8087 fire-control computer once upon a
time).


I've been in the real world for a long time, and the dumb
things people (including myself) do still surprise me.

Original Poster should send this off to thedailywtf.com
 
C

Christos Georgiou

BTW, my second post was doing ''.join(chr(int(h[i:i+2],16)) for i in xrange(0,16,2))
to undo the hexlify you had done (I'd forgotten that there's a binascii.unhexlify ;-)

And there's also str.decode('hex'), at least after 2.3 .
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,264
Messages
2,571,323
Members
48,008
Latest member
KieraMcGuf

Latest Threads

Top