编程判读此系统是大端还是小端

//判断此系统是大端还是小端的
//一个32位四字节的整数值,例如1,实际的计算机编码表示 是 0x00000001
//小端系统中在内存中的表示是 01 00 00 00
//大端系统中在内存中的表示是 00 00 00 01
#include <iostream>
using namespace std;
union EndianTest {  //union:共用内存地址
    int8_t u[4];    //8位整型的数组
    int32_t i;      //32位整型
};

static bool isLittleEndianSystem() {
    EndianTest et;
    et.i = 1;
    return et.u[0] == 1;
}
int main(int argc, char **agrv) {
    if(isLittleEndianSystem())
        cout << "This system is little endian
";
    else
        cout << "This system is big endian
";
    return 0;
}
原文地址:https://www.cnblogs.com/isChenJY/p/11510245.html