Search code examples
embeddedfixedpointnotation

Reverse Engineering Fixed Point Numbers


I am currently putting an engine into another car and I want to keep the fuel economy calulation inside the boardcomputer working. I managed to recode this part sucessfully, but I have been trying to figure out the (simple?) two byte dataformat they used without success. I assume it is fixed point notation, but no matter how I shift it around, it does not line up. How do the two bytes represent the right number?

Some examples:

Bytes (Dec) --> Result
174,10 -> 2,67 
92,11  -> 2,84
128,22 -> 3,75
25,29  -> 4,85
225,23 -> 3,98 
00,40  -> 5,00 
128,34 -> 5,75

Solution

  • Here's a partial solution:

    First, swap the bytes. Then join them:

    The result (in hex) is:

    0AAE
    0B5C
    1680
    1D19
    17E1
    2800
    2280
    

    Then split the into the first digit (4 bits), the remaining three digits (12 bits) and keep the entire number (16 bits) as well. The result (in decimal) is:

    0  2734   2734
    0  2908   2908
    1  1664   5760
    1  3353   7449
    1  2017   6113
    2  2048  10240
    2   640   8832
    

    The first digits seems to be a multiplication factor. 0 stands for 1024, 1 for 1536, 2 for 2048. The formula possibly is f = (1024 + n * 512).

    Now divide the entire number by the multiplication factor. The result, rounded to two decimal places, is:

     2734 / 1024 =  2.67
     2908 / 1024 =  2.84
     5760 / 1536 =  3.75
     7449 / 1536 =  4.85
     6113 / 1536 =  3.98
    10240 / 2048 =  5.00
     8832 / 2048 =  4.31
    

    It works for all except the last number, which might contain a mistake.

    So it seems to be some sort of floating-point number but I don't recoginze the specific format. Possibly, there is a simpler formula the explains the number.