From C

Jump to: navigation, search

Endianess refers to the ordering of bytes in a multi-byte number. Big endian refers to the architecture where the most significant byte has the lowest address, while the opposite Little endian, the most significant byte has the highest address.

Assuming that your machine is big or little-endian, you can find the endianess of your architecture using the following programming snippets:

int x = 1;
	if(*(char *)&x == 1)
	else	printf("big-endian\n");

#define BIG_ENDIAN    1

int machineEndianness()
   short s = 0x0102;
   char *p = (char *) &s;
   if (p[0] == 0x02) // Lowest address contains the least significant byte
      return LITTLE_ENDIAN;
      return BIG_ENDIAN;

Category Snippets

Personal tools