字节序: big-endian vs little-endian
如何快速記憶
big-endian又名大尾序,就是數值的尾巴存儲在大地址上。尾是相對我們認識的變量值,大是指地址;
相對應,little-endian又名小尾序,數值的尾巴存儲在小地址上。
一句話大小是尾巴的地址,尾巴是數值的尾巴,指的是0xABCD(十進制43981)的D
如何判斷字節序是大端還是小端
編譯出二進制
g++ main.cpp -o main
使用readelf查看字節序
readelf -h main
結果如下(ELF Magic第6個字節代表字節序,0 無效格式; 1 小端格式; 2 大端格式)
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2’s complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Machine: Advanced Micro Devices X86-64
Version: 0x1
Entry point address: 0x1060
Start of program headers: 64 (bytes into file)
Start of section headers: 14976 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 14
Size of section headers: 64 (bytes)
Number of section headers: 32
Section header string table index: 31
yms@yms-System-Product-Name:~/ws/thread_local$ lscpu | grep -i byte
Byte Order: Little Endian
yms@yms-System-Product-Name:~/ws$ ./main
little endian
網絡序
網絡傳輸一般采用大端序,也被稱之為網絡字節序,或網絡序。IP協議中定義大端序為網絡字節序。
總結
以上是生活随笔為你收集整理的字节序: big-endian vs little-endian的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Hello, Geant4
- 下一篇: 尺子英语怎么读计算机英语怎么读,尺子英语