Running the below code give me this result: 01010101.
Does this mean the machine places these bits from right to left? Is there any way to tell it to reverse the order? i.e the first bit in the struct (bit7) is the most significant bit. Do all machines work the same way? In another word, is the code portable?
#include <stdio.h>
#include <string.h>
#include <stdint.h>
struct dummyStruct_t
{
uint8_t bit7 :1;
uint8_t bit6 :1;
uint8_t bit5 :1;
uint8_t bit4 :1;
uint8_t bit3 :1;
uint8_t bit2 :1;
uint8_t bit1 :1;
uint8_t bit0 :1;
};
struct dummyStruct_t dummyStruct;
int main() {
uint8_t value = 0xAA;
memcpy(&dummyStruct, &value, sizeof(uint8_t));
printf("%d", dummyStruct.bit7);
printf("%d", dummyStruct.bit6);
printf("%d", dummyStruct.bit5);
printf("%d", dummyStruct.bit4);
printf("%d", dummyStruct.bit3);
printf("%d", dummyStruct.bit2);
printf("%d", dummyStruct.bit1);
printf("%d", dummyStruct.bit0);
return 0;
}