468,512 Members | 971 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

How to Know the processor is Big Endian or Little Endian

Been bothering me so long, what is the way to find the endians of processor ?I've tried using Union,but im getting result confused in understanding the outcome

anyone please help me
Aug 7 '06 #1
1 9715
9,056 Expert Mod 8TB
Normally processor on which it can be set also set a preprocessor symbol to indicate which endian is in use. If you really need to find it programatically

Expand|Select|Wrap|Line Numbers
  1. int i = 1;
  2. char *pc = (char *)&i;
  4. if ( *pc == 1 )
  5. {
  6.     /* little endian */
  7. }
  8. else
  9. {
  10.     /* Big endian */
  11. }
This of course assumes that the are only 2 endians, big and little. This assumption is not actually true although it does cover the majority of cases.
Aug 7 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Joe C | last post: by
8 posts views Thread by Perception | last post: by
2 posts views Thread by bhatia | last post: by
8 posts views Thread by ma740988 | last post: by
23 posts views Thread by guthena | last post: by
23 posts views Thread by Niranjan | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.