我不打算详细论述这个问题了,仅在这里提供我找到的几篇不错的介绍这个问题的文章在这里供大家参考。
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。由此可见,两台主机的字节序是一致的。