我知道小端和大端在网上已经解释了数千次,但我仍然很困惑。
如果您有一个设置为使用大尾数法的字节缓冲区。你有:
short value = 4660; // corresponds to 0x1234
当你这样做时:
bb.putShort( 16, value );
字节 0x12 位于索引 16 处,0x34 位于索引 17 处。还是 0x34 位于索引 16 处,0x12 位于索引 17 处?我对网上的描述感到困惑。
谢谢!
最佳答案
以0x12345678
为例。
一种看待它的方法:
Endianess | Least Significant Byte | Most Significant Byte | In Memory
----------|------------------------|------------------------|-----------
Big | In The Highest Address | In The Lowest Address | 0x12345678
----------|------------------------|------------------------|-----------
Little | In The Lowest Address | In The Highest Address | 0x78563412
另一种看待它的方式:
Endianess | In The Lowest Address | In The Highest Address | In Memory
----------|------------------------|------------------------|-----------
Big | Most Significant Byte | Least Significant Byte | 0x12345678
----------|------------------------|------------------------|-----------
Little | Least Significant Byte | Most Significant Byte | 0x78563412
<小时/>
如果您正在寻找一种方法来记住这一点,请注意每种方法都有其自己的意义:
- Big-Endian,因为它类似于我们书写数字的方式(从最高位开始)
- Little-Endian,因为最低有效字节存储在最低地址
关于java - 大端字节缓冲区中的字节顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24025499/