void byteorder()
{
union {
short value;
char union_bytes[sizeof(short)];
}test;
test.value = 0x0102;
if (test.union_bytes[0] == 1 && test.union_bytes[1] == 2)
{
cout << "大端" << endl;
}
else if (test.union_bytes[0] == 2 && test.union_bytes[1] == 1)
{
cout << "小端" << endl;
else {
cout << "error" << endl;
}
};