Do something to improve things. Anything. Start small or go big. Just do something. Today. Now. The world will be better for it. ----Just because no one else believes in your dreams doesn't mean you shouldn't believe in your dreams. ----The world is the great gymnasium where we come to make ourselves strong. "Swami Vivekananda"

Government Jobs In India Headline Animator

16 March 2011

How can I determine whether a machine's byte order is big-endian or little-endian?



The usual techniques are to use a pointer:
 int x = 1;
 if(*(char *)&x == 1)
  printf("little-endian\n");
 else printf("big-endian\n");


or a union:
 union {
  int i;
  char c[sizeof(int)];
 } x;
 x.i = 1;
 if(x.c[0] == 1)
  printf("little-endian\n");
 else printf("big-endian\n");

No comments:

Subscribe via email

Enter your email address:

Delivered by FeedBurner

website-hit-counters.com
Provided by website-hit-counters.com site.