Anyone recognize this numeric storage format - similar to "float", but not quite
geskerrett at hotmail.com
geskerrett at hotmail.com
Wed Aug 24 04:04:45 CEST 2005
We are working on a project to decipher a record structure of an old
accounting system that originates from the late80's mid-90's.
We have come across a number format that appears to be a "float" but
doesn't match any of the more standard implementations.
so we are hoping this is a recognizable number storage format with an
identifiable name AND pre-built conversion method
similiar to the "struct" modules available in python.
Here is what we have determined so far.
Example Number: 1234567890
This get stored on disk as 8 bytes, resulting in the following HEX
characters;
00 00 00 A4 05 2c 13 9f
If we changed the order so that it is "little Endian" we get;
9F 13 2c 05 A4 00 00 00
If the HEX is converted to binary it looks like;
10011111 00010011 00101100 00000101 10100100 00000000 000000000
00000000
If the example number 1234567890 is converted to binary it looks like;
10010011 00101100 00000101 1010010
To extract the example number, you need to do the following;
1) take the decimal value of the first byte and subtract 128
2) This tells you how many of the following bits to are significant and
must be read
3) Once the remaining bits are read, reverse the first bit of that
group (ie if it is a 0 make it a 1)
4) convert the result to decimal
... and presto, the example number !
Using a fixed width font it is easy to see the match at the bit level;
10011111 00010011001011000000010110100100000000000000000000000000
-------- 1001001100101100000001011010010
If you are interested, the following are three other examples;
Orig Hex: 00 00 00 60 92 96 72 A0
Actual Value: 4069954144
Orig Hex: 00 00 80 22 A3 26 3C A1
Actual Value: 6313297477
So ... does anyone recognize this ??
Is there a "built-in" conversion method in Python ??
Thanks in advance.
More information about the Python-list
mailing list