I'm currently struggling with modbus tcp and ran into a problem with interpreting the response of a module. The response contains two values that are encoded in the bits of an array of three UInt16
values, where the first 8 bits of r[0] have to be ignored.
Let's say the UInt16 array is called r
and the "final" values I want to get are val1
and val2
, then I would have to do the following:
In the above example the desired output values are val1
(=3) and val2
(=6) for the input values r[0]
=768, r[1]
=1536 and r[2]
=0, all values as UInt16.
I already tried to (logically) bit-rightshift r[0]
by 8, but then the upper bits get lost because they are stored in the first 8 bits of r[1]
. Do I have to concatenate all r-values first and bit-shift after that? How can I do that? Thanks in advance!