Hard to be sure because your question isn’t very clear. But perhaps this is what you want
uint16_t z = *reinterpret_cast<uint16_t*>(array);
Another possiblity is
uint16_t z = static_cast<uint8_t>(buf[0])*256 + static_cast<uint8_t>(buf[1]);
and another is
uint16_t z = static_cast<uint8_t>(buf[1])*256 + static_cast<uint8_t>(buf[0]);
Try them all, they differ only in what endianness they use. You should look that up.
One thing that is confusing me is that you say you want two bytes, but your z
variable is declared as uint8_t
which is one byte only. I changed it to uint16_t
.
1
solved C++ Convert part of the Array into int