Hi all,
I am communicating with a modbus device which sends data in 32 bits format.
The MSW represent the integer part of the value and the LSW represent the fractional part as an UINT16.
How can I transform that long into a float number with the right result?
Scale X .Y indicates a binary fraction where…
X specifies the number of integer bits
Y specifies the number of fractional bits
value = integer part + (fractional part / 2^Y)
Example:
Scale = 16.16 revs X = 16, Y = 16
Raw Value = 131109
131109 decimal = 10 00000000 00100101 B
integer part = 10 B = 2 decimal
fractional part = 00000000 00100101 B = 37 decimal
Final value = 2 + 37/2^16 = 2+16/32 = 2.000564
Thanks
Jose
I am communicating with a modbus device which sends data in 32 bits format.
The MSW represent the integer part of the value and the LSW represent the fractional part as an UINT16.
How can I transform that long into a float number with the right result?
Scale X .Y indicates a binary fraction where…
X specifies the number of integer bits
Y specifies the number of fractional bits
value = integer part + (fractional part / 2^Y)
Example:
Scale = 16.16 revs X = 16, Y = 16
Raw Value = 131109
131109 decimal = 10 00000000 00100101 B
integer part = 10 B = 2 decimal
fractional part = 00000000 00100101 B = 37 decimal
Final value = 2 + 37/2^16 = 2+16/32 = 2.000564
Thanks
Jose