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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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;