Solved

Get platform to know the endians

Posted on 2004-10-19
2
230 Views
Last Modified: 2010-04-01
Dear experts,
I need to know how to write a platform-indep C/C++ code that get the platform of the running machine. I need to know whether it is a big endian or little endian machine.

Thanx for fast response,
Amr
0
Comment
Question by:amradel_79
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Expert Comment

by:OnegaZhang
ID: 12346282
   int data = 0;
    char *p = (char*)&data;
    p[0] = 1;
    p[1] = 2;
    p[2] = 3;
    p[3] = 4;
    if(data == 0x01020304)
        std::cout<<"big endian"<<std::endl;
    else
        std::cout<<"little endian"<<std::endl;
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 12346301
http://upc.pkmn.co.uk/win32/littleend.html

inline int IsLittleEndian(){
  int i = 1 ;
  return (*((char *) &i )) ? 1 : 0;
}

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question