Let's say I have data, such as below:
union
{
struct
{
char flags : 4;
uint16_t : 12;
}
char data[2];
}
I understand how to make this code run regardless of byte endianness on a platform. I am asking to be sure that my understanding of how it would be stored on the different endians is correct.
As I understand it: If I were to store a uint16 in the 12 bit uint, both endians would drop the 4 highest bits. Big-endian would store the remaining 4 high bits in the same byte as the flags, and the rest in a separate byte. Little-endian would store the 4 lowest bits in the same byte as the flags, and the rest in a separate byte.
Is this right?