Reputation: 4841
so I have a Bytearray BYTE dataOut[3]
with the following data which I send out to a device.
unsigned int value = 512;
BYTE low_byte = 0xff & value;
BYTE high_byte = value >> 8;
dataOut[0]=SET_POSITION; //predefined
dataOut[1]=low_byte;
dataOut[2]=high_byte;
The device executes the command in this data packet. Then I call a read function which populates BYTE dataIn[3]
with data of the same format. How can I convert the bytes in dataIn[1]
and dataIn[2]
into an int value?
Thanks!
Upvotes: 0
Views: 5350
Reputation: 9457
value = (unsigned int)dataIn[2] << 8 + (unsigned int)dataIn[1]
should do it....
Upvotes: 4