字节序(Byte Oder)

blog.zhaojie.me/2010/02/byte-order-and-related-library.html


对于0x0A0B0C0D 它的有效位从高到低便是0A、0B、0C及0D

大字节序(big endian):最高有效位放在低地址上的存储方式

字节序(Byte Oder)


小字节序(little endian):最高有效位放在低地址上的存储方式






字节序(Byte Oder)


c语言来判断计算机是小端系统,还是大端系统

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdio.h>
 
union var{
    char c[8];
    int  i;  
};
 
int main(void){
    union var data;
    data.c[0] = 0x01;
    data.c[1] = 0x02;
    data.c[2] = 0x03;
    data.c[3] = 0x44;
    printf("p = %x",data.i);
}

结果为

44030201

此系统为小端系统.

本文转自神ge 51CTO博客,原文链接:http://blog.51cto.com/12218412/1866142