/* Matt Kretchmar September 3, 2014 Program to illustrate the "endian" of a machine by displaying byte order of an int */ #include int main ( void ) { int i; // char * points to first byte of int, must use typecast to avoid warning. unsigned char *ptr = (unsigned char *)&i; i = 0xf6543210; // print the int as hex, signed int, unsigned int printf("%x\n",i); printf("%d\n",i); printf("%u\n",i); unsigned char c; c = *ptr; // get first byte printf("First Byte : %x\n",c); ptr++; // advance pointer to next byte c = *ptr; printf("Second Byte : %x\n",c); ptr++; c = *ptr; printf("Third Byte : %x\n",c); ptr++; c = *ptr; printf("Fourth Byte : %x\n",c); return 0; }