Qual o endian?

int
main (int argc, char **argv){

	union {
		short s;
		char c[sizeof(short)];
	} un;

	un.s = 0x0102;

	if (sizeof(short) == 2){
		if (un.c[0] == 1 && un.c[1] == 2)
			printf("big-endian\n");
		else if (un.c[0] == 2 && un.c[1] == 1)
			printf("little-endian\n");
		else
			printf("Eu não entendi o que ele falou \n");
	}
	else
		printf("sizeof(short)==%d\n",sizeof(short));
}

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word