Calculation of Float data type
Posted: Wed 13. Nov 2019, 12:12
Hello PEAK,
I am creating a python script that converts CAN messages to the right information. Now we have a unit that uses the data type float. How are these converted to the correct decimal value in the PCAN Symbol Editor?
Because we get the data well in PCAN Explorer 6, but not if we want to convert a trc file to csv.
I have already found something how to convert the 4 bytes for float to decimal, but I do not come to the value that we see with PCAN Explorer 6.
I know that the 1st bit is used for the sign (VZ)(positive or negative). The following 8 bits are for the Exponent (e) and the remaining 23 bits for the Mantisse (M).
When I am going to calculate the following float 2D 40 2C 42 (0010 1101 0100 0000 0010 1100 0100 0010) this should be 43,06267166 in decimal. The 1st bit indicates 0 = VZ and means positive. Then the next 8 bits must be 'e'.
That is in hex 5A and in decimal 90 = e. The remaining bits give the value 1,5013506 =M . When I put this in the formula (-1)^VZ * M * 2^e = result. I get 1,0923764e^-11 but not 43,06267166.
Am I doing something wrong or is there another calculation that will get me the result we see with PCAN Explorer 6?
Kind regards,
Ruud van Dijk
I am creating a python script that converts CAN messages to the right information. Now we have a unit that uses the data type float. How are these converted to the correct decimal value in the PCAN Symbol Editor?
Because we get the data well in PCAN Explorer 6, but not if we want to convert a trc file to csv.
I have already found something how to convert the 4 bytes for float to decimal, but I do not come to the value that we see with PCAN Explorer 6.
I know that the 1st bit is used for the sign (VZ)(positive or negative). The following 8 bits are for the Exponent (e) and the remaining 23 bits for the Mantisse (M).
When I am going to calculate the following float 2D 40 2C 42 (0010 1101 0100 0000 0010 1100 0100 0010) this should be 43,06267166 in decimal. The 1st bit indicates 0 = VZ and means positive. Then the next 8 bits must be 'e'.
That is in hex 5A and in decimal 90 = e. The remaining bits give the value 1,5013506 =M . When I put this in the formula (-1)^VZ * M * 2^e = result. I get 1,0923764e^-11 but not 43,06267166.
Am I doing something wrong or is there another calculation that will get me the result we see with PCAN Explorer 6?
Kind regards,
Ruud van Dijk