How can I determine whether a machine's byte order is big-endian or little-endian?
One way is to use a pointer:
int x = 1; if(*(char *)&x == 1) printf("little-endian\n"); else printf("big-endian\n");It's also possible to use a union.
See also question 10.16.
References:
H&S Sec. 6.1.2 pp. 163-4
Read sequentially: prev next up top
This page by Steve Summit // Copyright 1995 // mail feedback