endian

Big Endian

In big endian, you store the most significant byte in the smallest address. Here's how it would look:

Little Endian

In little endian, you store the least significant byte in the smallest address. Here's how it would look:

Notice that this is in the reverse order compared to big endian. To remember which is which, recall whether the least significant byte is stored first (thus, little endian) or the most significant byte is stored first (thus, big endian).

int main(){ int x = 1; char *y = (char*)&x; printf("%c\n",*y+48);}

If it's little endian it will print 1. If it's big endian it will print 0.

Suppose we are on a 32-bit machine.

If it is little endian, the x in the memory will be something like:

higher memory -----> +----+----+----+----+ |0x01|0x00|0x00|0x00| +----+----+----+----+ A | &x

so (char*)(*x) == 1, and *y+48 == '1'.

If it is big endian, it will be:

+----+----+----+----+ |0x00|0x00|0x00|0x01| +----+----+----+----+ A | &x

so this one will be '0'.