记录网友的大小端两种 验证方式:
#include<iostream>
using namespace std;
int main()
{
int intBit = 0xABCD;
const char* testBit = (char *)(&intBit);
cout << hex;
cout << "内存中整数intBit的内容为:";
cout << (int(testBit[0]) & 0xff) << " ";
cout << (int(testBit[1]) & 0xff) << " ";
cout << int(testBit[2]) << " ";
cout << int(testBit[3]) << endl;
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////////
#include<iostream>
using namespace std;
union Endian
{
short data;
char ch[2];
};
int main()
{
Endian end;
end.data = 0xABCD;
cout << hex;
cout << (end.ch[0] & 0xff) << " " << (end.ch[1] & 0xff) << endl;
return 0;
}
https://blog.csdn.net/cylj102908/article/details/78697249