标签:
字节序分为 little-endian 和 big-endian,不同主机通信字节序转换过程:
主机字节序 -> 网络字节序 ->主机字节序
#include<arpa/inet.h>
int isBigEndian()
{
int flag = 0;
short a = htons(0x0102);
char* p = &a;
if(*p==0x01)
{
flag = 1;
}
return flag;
}
网络字节序为big-endian
int isBigEndian()
{
int flag = 0;
short a = 0x0102;
char* p = &a;
if(*p==0x01)
{
flag = 1;
}
return flag;
}
我的本地主机字节序为little-endian:
标签:
原文地址:http://www.cnblogs.com/ZhangJinkun/p/4530231.html