/*
 * showendian.c
 * Steve Shah (sshah@planetoid.org)
 *
 * Simple test to show "endian-ness". For more information on the
 * difference between big-endian and little-endian see 
 * http://www.webopedia.com/TERM/b/big_endian.html
 *
 * gcc -Wall -pedantic -ansi showendian.c -o showendian
 *
 * Should easily compile with other C compilers and other OS's.
 *
 */

#include <stdio.h>

int main ()
{
int x;
union {
	unsigned short int s;
	unsigned char c[2];
} u1;
union {
	unsigned int i;
	unsigned char c[4];
} u2;

	u1.s = 0x1234;
	printf ("u1.s = %04x, ", u1.s);
	printf ("u1.c = %02x%02x\n", u1.c[0], u1.c[1]);

	u2.i = 0x12345678;
	printf ("u2.i = %08x, u2.c = ", u2.i);
	for (x=0;x<4;x++) {
		printf ("%02x", u2.c[x]);
	}
	printf ("\n");

	if (u1.c[0] == 0x34) {
		printf ("Your machine is little endian. (e.g., x86)\n");
	} else {
		printf ("Your machine is big endian (e.g., MIPS, SPARC)\n");
	}

	return 0;
}


