利用union判断CPU是大端模式还是小端模式
#include <iostream>
using namespace std;
int checkCPU()
{
	union w
	{
		int a;
		char b;
	} c;
	c.a = 1;
	return c.b == 1;//如果低地址还是1说明低地址存放低字节,小端 
}//如果低地址不是1,则高地址是1,说明低地址存放高字节,大端 
int main()
{
	if (checkCPU())
	{
		cout << "The endian of cpu is little \n";
	}
	else
	{
		cout << "The endian of cpu is big \n";
	}
	return 0;
}========================================Talk is cheap, show me the code=======================================
    CSDN博客地址:https://blog.csdn.net/qq_34115899
 
                     
                    
                 
                    
                 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号