网络大小端转换函数
網(wǎng)絡大小端轉(zhuǎn)換函數(shù)
//***************************************************************************** // // htonl/ntohl - big endian/little endian byte swapping macros for // 32-bit (long) values // //***************************************************************************** #ifndef htonl static uint32_t htonl(uint32_t a) {return ((a >> 24) & 0x000000ff) |((a >> 8) & 0x0000ff00) |((a << 8) & 0x00ff0000) |((a << 24) & 0xff000000); } #endif#ifndef ntohl #define ntohl(a) htonl((a)) #endif//***************************************************************************** // // htons/ntohs - big endian/little endian byte swapping macros for // 16-bit (short) values // //***************************************************************************** #ifndef htons static uint16_t htons(uint16_t a) {return ((a >> 8) & 0x00ff) | ((a << 8) & 0xff00); } #endif#ifndef ntohs #define ntohs(a) htons((a)) #endif
總結(jié)
- 上一篇: VS2015一键卸载所有组件工具,彻底卸
- 下一篇: 浅析物联网及云计算技术在传统汽车检测线中