1. 程式人生 > >測試我自己的系統是大端還是小端

測試我自己的系統是大端還是小端

結果證明:是小端儲存。

#include <iostream>
#include <vector>
#include <stack>
using namespace std;

int checkCPU()
{
        union w
        {
            int a;
            char b;
        }c;
        c.a = 1;
        return (c.b == 1);//小端返回1,大端返回0
}


int main()
{
    int flag= checkCPU();
    cout
<<flag<<endl; return 0; }

運算元高位存記憶體地址高位:

比如:

地址      資料

0x4000 0x78

0x4001 0x56

0x4002 0x34

0x4003 0x12