I have the following struct:
struct SysData { // Topic (32 bits) UTL_UINT16_Tdef SystemID:11; // set to decimal 25 UTL_UINT16_Tdef TypeID:5; // set to 2 (telemetry type) UTL_UINT16_Tdef ContentID; // set to decimal 1234 } SysData MsgHdr; MsgHdr.SystemID = 25; MsgHdr.TypeID = 2; MsgHdr.ContentID = 0; If I do something like this:
unsigned int a; memcpy(&a, &MsgHdr, sizeof(MsgHdr)); headerInfo[0] = a & 0x7FF; headerInfo[1] = (a >> 16) & 31; headerInfo[2] = (a >> 21) & 0xFFFF; headerInfo[0] should have the value 25, but it has 36. What am I doing wrong?
headerInfo?unionnot be suitable?headerInfo[1]andheaderInfo[2]aren't what I'd expect them to be:(a >> 11) & 31and(a >> 16) & 0xffff