Friday, 5 April 2013

How to Decide Given Processor Is Little Endian or Big Endian

 What are Little Endian and Big Endian

Big endian and little endian are the  terms,that tells the order in which sequence bytes are stored in memory.

Big Endian

Big Endian-Most Significant byte is stored at the lowest address.

Little Endian 

Little Endian-lest Significant byte is stored at he lowest address.

The binary representation of integer 5193 in 2 bytes is



0001  0100       0100 1001
 MS byte            LS byte


The following  figure show how this integer is stored in different byte order

Little Endian 

 Address:-


 2000            0100    1001  LSB
 2001            0001    0100  MSB


Big Endian 

Address:-


2000         0001 0100  LSB
2001         0100 1001  MSB

By write a below program we can find little Endian machine and Big Endian machine.


#include<stdio.h>
int main()
{
    unsigned int k=1;
    char*c=(char*)&k;
    if(*c)
    printf("Little endian");
    else
    printf("Big endian");
    getchar();
    return(0);
    system("pause");
}         
                                       
                                              

  

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More