I have a pressure sensor from Infineon DPS310. There are two's complement values in 12 bit and some are in 24 bits. I want to process them with the right datatype.
Is uint16_t/uint32_t are okey or int16_t/int32_t is a better choice?
Also, I don't understand the following code which I found online for two's complement conversion. Can someone tell is this the correct code?
Code: Select all
static int32_t twosComplement(int32_t val, uint8_t bits) {
if (val & ((uint32_t)1 << (bits - 1))) {
val -= (uint32_t)1 << bits;
}
return val;
}