voidread(int data){ printf("data is %d\n", data); printf("bytes order of data is"); show_int(data); char* pa = (char*) &data; int big_data = (pa[3]<<0) | (pa[2]<<8) | (pa[1]<<16) | (pa[0]<<24); int little_data = (pa[0]<<0) | (pa[1]<<8) | (pa[2]<<16) | (pa[3]<<24); printf("big_endian order data is %d\n", big_data); printf("little_endian order data is %d\n", little_data); }
intmain(int argc, charconst *argv[]) { int a = 12345; show_int(12345); show_float(12345.6789); printf("%p\n", &a); show_pointer(&a);
int data = 0x01234567; read(data); printf("--------After swap bytes order--------\n"); data = swapInt32(data); read(data); return0; }
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13
39300000 b7 e6 4046 0x7ffee5f20b5c 5c 0b f2 e5 fe 7f0000 data is 19088743 bytes order of data is 67452301 big_endian order data is 1732584193 little_endian order data is 19088743 --------After swap bytes order-------- data is 1732584193 bytes order of data is 01234567 big_endian order data is 19088743 little_endian order data is 1732584193