Reference
- ARM Datasheet
https://www.freecodecamp.org/news/what-is-endianness-big-endian-vs-little-endian/
https://zhuanlan.zhihu.com/p/360037797
Background (Why)
Endianness Overview (What)
- BE stores the big-end first. When reading multiple bytes the first byte (or the lowest memory address) is the biggest - so it makes the most sense to people who read left to right.
- LE stores the little-end first. When reading multiple bytes the first byte (or the lowest memory address) is the littlest - so it makes most sense to people who read right to left.
- BE vs LE
-
Examples (How)
X86 is LE; ARM is LE by defaut (but supports BE also).
- 网络字节序
TCP/IP协议隆重出场,RFC1700规定使用“大端”字节序为网络字节序。
- unsinged int 类型数据在内存的存储方式 (对于大于一个字节的基本数据类型,CPU都会以一定的 order 按 byte 读取数据)
- Struct 类型数据在内存的存储方式(对于复合数据类型,CPU按照其子元素的基本数据类型读取数据,另外会考虑内存对齐)
下面是在 X86_64 上实现的例子(小端模式)