首页 > 其他 > 详细

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

时间:2019-09-12 10:04:20      阅读:119      评论:0      收藏:0      [点我收藏+]
//判断此系统是大端还是小端的
//一个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\n";
    else
        cout << "This system is big endian\n";
    return 0;
}

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

原文:https://www.cnblogs.com/isChenJY/p/11510245.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!