C- Determining start of a Bit-field using a Union -


for example below, based on how bits.b.a set value of bits.byte, mean head of bit-field? know machine little-endian doesn't mean least significant bit or significant bit. there better way determine order of bit-field through coding?

struct bit_fields {     unsigned int a:4,                  b:8,                  c:20; } union myunion {      bit_fields b;     uint8_t byte; } int main(void) {     union myunion bits;     bits.byte=1;     printf("%u, %u, %u\n", bits.b.a, bits.b.b, bits.b.c);     return 0; }   output:  1, (random int less 2^8), (random int less 2^20) 


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -