字节排序问题
字节排序问题
小端字节序:变量的低位 存储在 内存地址的低位。
主机字节序:某个给定操作系统的字节序,不同操作系统的字节序不同,可能是大端也可能是小端。
网络字节序:规定网络传输信息的时候使用的字节序,一般为大端字节序。
四个字节序转换函数:
#include <netinet/in.h>
uint16_t htons(uint16_t host16bitvalue);
uint32_t htonl(uint32_t host32bitvalue); //返回网络字节序的值
uint16_t ntohs(uint16_t net16bitvalue);
uint32_t ntohl(uint32_t net32bitvalue); //返回主机字节序的值