*** 自写代码:判断CPU是Big Endian还是Little Endian

#include <iostream>
#include <string.h>
using namespace std;
bool checkLittleEnd (void)
{
    union test
    {
        int a;
        char b;
    } t;
    t.a = 1;
    return (t.b==1);
}
int main()
{
    if (checkLittleEnd())
        cout << "Little End!" << endl;
    else
        cout << "Big End!" << endl;
    return 0;
}

 

posted @ 2018-12-23 18:53  super行者  阅读(222)  评论(0编辑  收藏  举报