I am trying to save a uint32 value to a modbus implementation where the registers are declared as signed short (should be the same as int16?).
Code that should represent what I am trying to do:
Problem is that when the number to be splitted (x) exceeds 0x8000 the 16 higest bits is 0xFFFF after reconstruction.
Would appreciate if anybody would help me understand what I have missed.
Code that should represent what I am trying to do:
Code:
uint32_t x = 0x8000; int16_t a; int16_t b; //Split a = x >> 16; b = x & 0x0000FFFF; //Reconstruction x = (uint32_t)a << 16 | (uint32_t)b
Would appreciate if anybody would help me understand what I have missed.
Comment