每次看到計算機大端和小端的概念,都需要查閱資料確認下哪一種是大端,哪一種是小端。
所以,特意寫這個文章總結下,期望之後不用查資料也能記住大端和小端。
簡要記憶:
大端——數據尾端是高地址,
小端——數據尾端是低地址。
TCP/IP協議棧採用大端字節序。
以32位整數爲例,具體如下:
大端:
小端:
nginx源碼驗證大端和小端:
#include <stdio.h>
int main() {
int i = 0x11223344;
char *p;
p = (char *) &i;
if (*p == 0x44) {
printf("Little endian\n");
}
else {
printf("Big endian\n");
}
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14