I have a incoming packet of 75 bytes. It is packed of five 10 Bitters and five 5 Bitters. like 10-5-10-5-... What is the best way to receive-parse-modify and send the packet back using struct/union or any ther way. :o
Printable View
I have a incoming packet of 75 bytes. It is packed of five 10 Bitters and five 5 Bitters. like 10-5-10-5-... What is the best way to receive-parse-modify and send the packet back using struct/union or any ther way. :o
Use bit fields: http://msdn.microsoft.com/en-us/libr...=vs.71%29.aspx
Pretty sure you will also need the extern "C" for this, because C++ will pad however it wishes.
No, he won't need to extern it. C++ will not pad it if he builds his struct properly.
Always try to allign your packed structs on word boundries, at the very least.Code:struct SomeBits
{
unsigned short first_10_bits : 10;
unsigned char next_5_bits : 5;
unsigned short next_10_bits : 10;
unsigned char next_5_bits : 5;
unsigned short next_10_bits : 10;
unsigned char next_5_bits : 5;
unsigned short next_10_bits : 10;
unsigned char next_5_bits : 5;
unsigned short next_10_bits : 10;
unsigned char next_5_bits : 5;
unsigned char pad :5;