其他分享
首页 > 其他分享> > 在主机和网络字节顺序之间转换值 的4个函数 ------- htonl, htons, ntohl, ntohs

在主机和网络字节顺序之间转换值 的4个函数 ------- htonl, htons, ntohl, ntohs

作者:互联网

简单的说这些函数就是: 将一个数的高低位互换

主机字节顺序成为小端,网路字节顺序成为大端。

原型:

#include <arpa/inet.h>
uint32_t htonl(uint32_t hostlong);
uint16_t htons(uint16_t hostshort);
uint32_t ntohl(uint32_t netlong);
uint16_t ntohs(uint16_t netshort);

函数描述信息:

htonl函数:将无符号整数hostlong从主机字节顺序转换为网络字节顺序。

htons函数:将无符号短整数hostshort从主机字节顺序转换为网络字节顺序。

ntohl函数:将无符号整数netlong从网络字节顺序转换为主机字节顺序。

ntohs函数:将无符号短整数netshort从网络字节顺序转换为主机字节顺序。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 



标签:顺序,htonl,字节,主机,ntohl,uint16,ntohs,uint32,函数
来源: https://www.cnblogs.com/ruigelwang/p/13158497.html