#include <iostream> //stderr, fprintf #include <arpa/inet.h> using namespace std; int main(int argc, char **argv) { unsigned int data = 0x19490738; unsigned char *str = (unsigned char *) &data; fprintf(stderr, "%x ", *str); // Network byte order(big endian), so big(19) is first. unsigned int hdata = htonl(data); str = (unsigned char *) &hdata; fprintf(stderr, "%x ", *str); return 0; }
测试结果:
[biglitEndian]$ g++ -o testBigLit testBigLit.cpp [biglitEndian]$ ./testBigLit 38 19