//大小端判断
#include <iostream>
bool endian_big_little_pointer();
bool endian_big_little_union();
int main()
{
if(endian_big_little_pointer() && endian_big_little_union())
std::cout<<"big endian"<<std::endl;
else
std::cout<<"little endian"<<std::endl;
}
//利用位操作判断大小端
bool endian_big_little_pointer(){
int V = 0x0D0C;
char c = *(char*)(&V);
if(c == 0x0D)
return true;
else
return false;
}
//利用C语言的union结构判断大小端
bool endian_big_little_union(){
union endian{
int a;
char b;
}flag;
flag.a = 1;
return (flag.b != 1);
}
#include <iostream>
bool endian_big_little_pointer();
bool endian_big_little_union();
int main()
{
if(endian_big_little_pointer() && endian_big_little_union())
std::cout<<"big endian"<<std::endl;
else
std::cout<<"little endian"<<std::endl;
}
//利用位操作判断大小端
bool endian_big_little_pointer(){
int V = 0x0D0C;
char c = *(char*)(&V);
if(c == 0x0D)
return true;
else
return false;
}
//利用C语言的union结构判断大小端
bool endian_big_little_union(){
union endian{
int a;
char b;
}flag;
flag.a = 1;
return (flag.b != 1);
}