I have a functional formula in Excel which I am trying to replicate in C++ for my project. For a little context, these are individual wheel speeds read via CAN in my BMW car project.
The captured data from the CAN bus is as per the below example. It consists of 8 bytes containing hex values where two bytes are used for each wheel.
unsigned char buf[8];
An example of a payload would be:
87 22 7F 2 81 2 80 2
The formula which is working as expected in Excel is shown below and in text for the first wheel:
the formula in your code is different from the one in your post
(HEX2DEC(B0)+HEX2DEC(RIGHT(B1,1))*256)/16
which is correct?
what should be the result from
The image from Excel shows what the expected result is, the payload being in yellow and the results in green with the formula below showing how it was achieved. The column headings B0, B1 etc are the bytes of the payload.
Many thanks for the tip I shall investigate this angle and your supplied changes. To clarify, I do want integer / float results (km/h) and that's what the Excel results are in (green cells).
Yes, will get it functional first then optimise things.
I went away and read up on the bitwise & operator and makes sense now the changes proposed by @oqibidipo !! Tested and at least stationary the results look good
Will validate after work today with a proper drive !!