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;
  }
10  }
11  int main(int argc, char* argv[])
12  {
13    printf("My Processor is %s Endian.\n", cpu_endian() < 0 ? "Little" : "Big");
14  }
15 
16 
17  Output:
18  My Processor is Little Endian.
19 

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

 Vote 0

Similar topics related to this section

setjmp and longjmp, trace a memory leak, detect memory corruption, Big Endian and Little Endian, stack grows up or down, C and Data Structures, Data Structures using array,

# C Programming Language (Prentice Hall Software)
# Let Us C Paperback - 2006 by Yashavant Kanetkar
# Understanding and Using C Pointers Core techniques for memory management
# Data Structures Using C and C++ Paperback - 1998
# Data Structures In C Paperback - August 11, 2008 by Noel Kalicharan