There are two types of processor available. They are "Little Endian" and "Big Endian". Very good example of Little Endian processors are Intel x86 based processors whereas Motorola and some few processors are mostly Big Endians.

How they differ depends on how they manage byte content in 32/64bit register. A Little endian CPU manage lower bytes in lower bit offfets which uniformly matches from LSB towards MSB. Whereas Big Endian processor manages bytes in reverse order. Lowet byte goes in most significat bits and gradually upper bytes are managed in lower bits. Below diagram shows how bytes are arranged in 32bit registers.

Big Endian and Little Endian

One point to note here is compiler and assembler takes care of the bitwise and shifting operations we do in our C/ASM programs. We can detect the difference only when we access row bytes in a 32bit registers. Below program show how to detect endianess from C program.

int cpu_endian(void)
  unsigned int reg = 0x1;
  if ((*(unsigned char *)&reg) == 1) {
    return -1;
  } else {
    return 1;
int main(int argc, char* argv[])
  printf("My Processor is %s Endian.\n", cpu_endian() < 0 ? "Little" : "Big");

My Processor is Little Endian.

About our authors: Team EQA

You have viewed 1 page out of 248. Your C learning is 0.00% complete. Login to check your learning progress.