ASCII art:
MSB LSB +----+----+----+----+----+----+----+----+ |a4.1|a4.0|a3.1|a3.0|a2.2|a2.1|a2.0| a1 | +----+----+----+----+----+----+----+----+ | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | +----+----+----+----+----+----+----+----+ | 0x9 | 0x4 | +----+----+----+----+----+----+----+----+
As noted, behavior is determined by implementation; this is one of two legitimate ways to organize data and, apparently, the format chosen on your computer. Alternative behavior.
MSB LSB +----+----+----+----+----+----+----+----+ | a1 |a2.2|a2.1|a2.0|a3.1|a3.0|a4.1|a4.0| +----+----+----+----+----+----+----+----+ | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | +----+----+----+----+----+----+----+----+ | 0x2 | 0x6 | +----+----+----+----+----+----+----+----+
This was apparently the behavior you were expecting.
Since this is a specific implementation, you can look in the manual and find out what your compiler does, because the compiler must document its behavior.
If you have portability to worry about, you need to think about how you organize your structure definitions in order to work the way you need to work on every platform you use.
source share