Re: 13 bit bitfield

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



If what you want to store is basically the On and Off state of each position
for 13 bits then probably what you want is "bitset"
It is a part of STL am sure you can use it on the on the Microsoft compiler.

Ganga

"Jason Spence" <jspence@xxxxxxxxxx> wrote in message
news:eTU2xo8kGHA.4816@xxxxxxxxxxxxxxxxxxxxxxx
I'm trying to define the IPv4 header using bitfields. The fragment flags
and offset look like this:

0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Identification |Flags| Fragment Offset |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
I tried this:typedef struct IPV4_HDR{...uint16_t ip_id; /* identification
*/uint16_t ip_mf:1; /* more fragments flag */uint16_t ip_df:1; /* dont
fragment flag */uint16_t ip_evil:1; /* evil bit */uint16_t ip_fo:13; /*
fragment offset */...} IPV4_HDR;Which results in this
packing:|OOOOOOOO|FFFOOOOO|Where the Os are the fragment offset and the Fs
are the flag bits. As you can see,the 13 bit field is byte swapped, as
you'd expect if the 13 bit field reallywas an unsigned short. But this
isn't how the field is layed out on the wire.Is there any way to do this
using bitfields on the Microsoft compiler?




.