471,873 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,873 software developers and data experts.

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 9814
Banfa
9,065 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;
  3.  
  4. if ( *pc == 1 )
  5. {
  6.     /* little endian */
  7. }
  8. else
  9. {
  10.     /* Big endian */
  11. }
  12.  
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 YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.