Search

Sponsored Links

Meta

Categories

Archives

Recent Posts

RSS Feeds

25
Oct

Finding endianness

Related Blog Items

to know about endianness, please refer to my earlier posts…
Little, Big endianess explained
Little, big endianess explained - part2

here is the snippet for finding endianness…

 
//returns zero for little endian
//returns 1 for big endian
//otherwise some error occured
int find_endianness()
{
  int x = 0x01 ;
  if (* (char *) &x == 1)
  {
    //little endian
    return 0;
  }
  else if (*((char *)&x+sizeof(int)-1)==1)
  {
    //big endian
    return 1;
  }
  else
  {
    //could not find what we have written in that byte
    return -1;
  }  
 
  return 0;
}

Popularity: 20%

You need to log on to convert this article into PDF


Related Blog Items

2 Comments

Leave a comment

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image