big-endian 与 little-endian 以及网络字节序

       我不打算详细论述这个问题了,仅在这里提供我找到的几篇不错的介绍这个问题的文章在这里供大家参考

                  1.Writing endian-independent code in C:点击打开链接

                  2.Understanding Big and Littel Endian Byte Order:点击打开链接

                    

             在参考1中“Network byte order”小节,有这样一段话:"Suppose an 80x86-based PC is to talk to a SPARC-based server over the Internet. Without further manipulation, the 80x86 processor would convert 192.0.1.2 to the little-endian integer 0x020100C0 and transmit the bytes in the order 02 01 00 C0. The SPARC would receive the bytes in the order 02 01 00 C0, reconstruct the bytes into a big endian integer 0x020100c0, and misinterpret the address as 2.1.0.192. " 根据这段话,我想解释为什么在通常情况下,即大家使用的都是基于intel的little-endian字节序的两台主机之间通信,不必考虑endian问题。

       假设int型的数值:0x01234567(at 0x100):

         

             对于两台采用little-endian的主机来说,发送方将按照网络字节序发送,即:0x01,0x23,0x45,0x67.接收端将按照0x01,0x23,0x45,0x67来接收,组合为0x01234567。由此可见,两台主机的字节序是一致的。

            

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值