I decedied not to use MACROS for the bitwise operations but rather use BitSet. Basically what i am intending to do is, I receive a struct evaluate its bits then appened them to another struct.
I receive a Struct, say:
typedef struct{
uint8 status; //!< Status
} MsgStatus;
I need to get the status and check each received bit, so i create a bitset of the recevied struct:
m_msgBits = new MsgStatus();
bitset<8> msgBits(m_msgBits->status);
// I evaluate the bits
Now, after the evaluation I need to appened the received bits to another struct, say:
typedef struct{
uint32 status; //!< Status
} MsgOverallStatus;
So, what i do is:
m_OverallStatus = new MsgOverallStatus();
bitset<16> overallBits(m_OverallStatus->status);
m_OverallStatus.reset(); // 00000000 00000000
//Then append bits in msgBits in overallBits, for example:
overallBits.set(0, msgBits[0]);
overallBits.set(1, msgBits[1]);
overallBits.set(2, msgBits[2]);
//==== HERE WHERE I DUNNO HOW TO DO IT ====
m_OverallStatus->status = overallBits;
I want to assign the bits to the struct field, i get this error: cannot convert ‘std::bitset<16u>’ to ‘uint16’ in assignment
I dont want to change the struct field type, so what can I do? I apologize for how silly is my question.
Thanks in advance
Use
std::bitset‘s member functionto_ulong, which returns the bits in the set as anunsigned long.