大小端和字节序

2018-06-18 04:02:18来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

1. middle-endian/mixed-endian

https://en.wikipedia.org/wiki/Endianness#Middle-endian

 

2. When is htonl(x) != ntohl(x) ?

https://stackoverflow.com/questions/11617684/when-is-htonlx-ntohlx-or-when-is-converting-to-and-from-network-byte-o

So, a crazy machine may have a 8 bits right rotated from network byte order as its host byte order. On such a machine, htonl and ntohl would not be the same. htonl would have to rotate left by 8 bits, and ntohl would have to rotate right by 8 bits. – jxh May 22 '15 at 3:08

 

3. 用一个语句判断大小端

1 int isLittleEndian(void)
2 {
3     return *(char *)(int []){1} == 1;
4 }

关于Compound Literals,https://gcc.gnu.org/onlinedocs/gcc-3.3.1/gcc/Compound-Literals.html

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:基础练习——完美的代价

下一篇:PAT (Basic Level) Practise (中文)-卡拉兹(Callatz)猜想