uint16_t value = lowByte & highByte; //combine, but the result is 0.
This is not how you combine two bytes into a single uint16_t
: you are AND
ing them in place, while you need to shift the high byte, and OR
it with the low byte:
uint16_t value = lowByte | (((uint16_t)highByte) << 8);
However, this is suboptimal in terms of readability: if you start with a 32-bit integer, and you need to cut out the upper 16 bits, you could simply shift by 16, and mask with 0xFFFF
- i.e. the same way that you cut out the third byte, but with a 16-bit mask.