Hi guys, How do you convert a uint8_t to a uint16_t?
currently im breaking down uint16_t to uint8_t like this:
packetBuffer.header[0] = ((co2Val>>8) & 0xff);
packetBuffer.header[1] = (co2Val & 0xff);
packetBuffer.header[2] = ((humVal>>8)&0xff);
packetBuffer.header[3] = (humVal & 0xff);
packetBuffer.header[4] = ((tempVal>>8)&0xff);
packetBuffer.header[5] = (tempVal & 0xff);
co2Val,humVal and tempVal are all uint16_t
however, i'll need to change them back to get the corresponding value. This is received at the other end as uint8_t buf[16].
this is how i did it:
CO2Val = (buf[0]<<8)|buf[1];
HumVal = (buf[2]<<8)|buf[3];
HumVal = (HumVal & 0x0fff);
TempVal = (buf[4]<<8)|buf[5];
TempVal = (TempVal & 0x3fff);
The results are different. Anyone know why? thanks