PracticeDev/test/endian_test.cpp

25 lines
591 B
C++
Raw Normal View History

2022-12-20 17:31:11 +08:00
/*************************************************************************
> File Name : endian_test.cpp
> Author : TL Song
> EMail : songtianlun@frytea.com
> Created Time : Fri 18 Dec 2020 02:16:02 PM CST
************************************************************************/
#include <iostream>
using namespace std;
int main()
{
union {
short val;
char c[sizeof(short)];
} test;
test.val = 0x0102;
if (test.c[0] == 0x01 && test.c[1] == 0x02)
cout << "big endian" << endl;
else
cout << "little endian" << endl;
return 0;
}