In VStudio 2010, I'm trying to create a union to access a 2-byte value conveniently:
#pragma pack(push,1) // disable padding
typedef struct {
uint8_t r:3;
uint8_t g:3;
uint8_t b:3;
}tsRgb;
typedef union {
uint16_t raw;
tsRgb rgb;
}tPixelData;
#pragma pack(pop)
int main(){
tPixelData pixel;
pixel.raw = 0xABE5;
return 0;
}
I'm expecting to see pixel.r = 5, pixel.g = 4, pixel.b = 7. the r and g are ok, but the b is 3.
What am I doing wrong? I assume I'm not alligning the bits correctly?