I want to store a 4-byte int in a char array... such that the first 4 locations of the char array are the 4 bytes of the int.
Then, I want to pull the int back out o
int main() { typedef union foo { int x; char a[4]; } foo; foo p; p.x = 0x01010101; printf("%x ", p.a[0]); printf("%x ", p.a[1]); printf("%x ", p.a[2]); printf("%x ", p.a[3]); return 0; }
Bear in mind that the a[0] holds the LSB and a[3] holds the MSB, on a little endian machine.