Link to home
Start Free TrialLog in
Avatar of amradel_79
amradel_79

asked on

Get platform to know the endians

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
Avatar of OnegaZhang
OnegaZhang

   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;
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial