25 lines
591 B
C++
25 lines
591 B
C++
|
/*************************************************************************
|
||
|
> 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;
|
||
|
}
|