I'm using a data structure in C like the following that contains a bit field and uses the colon to define the number of bits.

typedef bitfield{

uchar x:6,

uchar y:2;

uchar z;

} BITFIELD;

//assume msb packing such that x is 6 most significant bits and y is 2 least sig. bits

In my code if I have a byte value and then assign it to the type members, will the least significant bits always be assigned to the bit field variable, or, will the assignment take into account the correct number of bits as shown below?

//pseudo code

BITFIELD mybitfield;

uchar data = 0xFC; // 1111 1100

mybitfield.x = data;

mybitfield.y = data;

mybitfield.z = data;

at this point I think the following values are stored

mybitfield.x = 0x3F //111111 six most sig. bits

mybitfield.y = 0x00 //00 two least sig. bits

mybitfield.z = 0xFC

Is this correct?

Thanks.

typedef bitfield{

uchar x:6,

y:2;

uchar z;

} BITFIELD;

(note the comma after the 6)