Does any one recognize this binary data storage format
Grant Edwards
grante at visi.com
Wed Aug 10 09:31:53 EDT 2005
On 2005-08-10, Bengt Richter <bokr at oz.net> wrote:
> On Tue, 09 Aug 2005 21:50:06 -0000, Grant Edwards <grante at visi.com> wrote:
>
>>On 2005-08-09, Scott David Daniels <Scott.Daniels at Acm.Org> wrote:
>>> Grant Edwards wrote:
>>>>>Ex #1) 333-3333
>>>>>Hex On disk: 00 00 00 80 6a 6e 49 41
>>>>>
>>>>>Ex #2) 666-6666
>>>>>Hex On disk: 00 00 00 80 6a 6e 59 41
>>>>
>>>> So there's only a 1-bit different between the on-disk
>>>> representation of 333-3333 and 666-6666.
>>>>
>>>> That sounds pretty unlikely. Are you 100% sure you're looking
>>>> at the correct bytes?
>>>
>>> Perhaps the one bit is an exponent -- some kind of floating point
>>> based format? That matches the doubling of all digits.
>>
>>That would just be sick. I can't imagine anybody on an 8-bit
>>CPU using FP for a phone number.
> >>> def double_binary_lehex_to_double(dhex):
> ... "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)[s]*f*2.0**x
> ...
> >>> double_binary_lehex_to_double('000000806a6e4941')
> 3333333.0
> >>> double_binary_lehex_to_double('000000806a6e5941')
> 6666666.0
> >>> double_binary_lehex_to_double('0000108777F9Fc41')
> 7777777777.0
>
> ;-)
Damn.
I still say that's just plain sick.
--
Grant Edwards grante Yow! NEWARK has been
at REZONED!! DES MOINES has
visi.com been REZONED!!
More information about the Python-list
mailing list