【发布时间】:2013-08-19 01:11:36
【问题描述】:
我在主机(取决于 CPU)和网络(大端)之间转换字节顺序时遇到问题。这些是我发现的所有 API(在 Linux 的“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);
除了一件事,它们只处理无符号整数(2字节或4字节)。
那么有没有办法处理有符号整数大小写?也就是说,如何实现以下函数(API)?
int32_t htonl(int32_t hostlong);
int16_t htons(int16_t hostshort);
int32_t ntohl(int32_t netlong);
int16_t ntohs(int16_t netshort);
【问题讨论】:
标签: c endianness