/* endian_test.c - test that arithmetic shifting works to build integers * Andrew Ho (andrew@zeuscat.com) * * I've been building a lot libraries that read and write binary files, * and always use network byte order to store integers on disk. This is * just a quick sanity check to prove that using C << and >> operators * does this correctly (that is, that they do an arithmetic shift) when * applied at least to unsigned integers. * * To be useful you really need to run this on two different architectures * whose endianness is different (I use Intel and Sparc). * * Build: gcc -Wall -o endian_test endian_test.c * Usage: endian_test */ #include #include int main(int argc, char **argv) { unsigned char i = 0x01, j = 0x02; unsigned int k = j | (i << 8); printf("i = 0x%02x, j = 0x%02x, k = 0x%04x\n", i, j, k); return 0; }