Solved

Get platform to know the endians

Posted on 2004-10-19
2
234 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

623 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