标签:blog io ar strong 数据 div sp on c
大端法:高位字节排放在内存低地址端,低位字节排放在内存的高地址端。
小端法:低位字节排放在内存的低地址端,高位字节排放在内存的高地址端。
看一个unsigned short 数据,它占2个字节,给它赋值0x1234。
若采用的大端法,则其低地址端应该存放的是0x12;
若采用的小端法,则其低地址端应该存放的是0x34;
#include <stdio.h>
typedef union{
unsigned short value;
unsigned char bytes[2];
}Test;
int main(void)
{
Test test_value;
test_value.value = 0x1234;
if(test_value.bytes[0] == 0x12 && test_value.bytes[1] == 0x34)
printf("big ending");
else if(test_value.bytes[0] == 0x34 && test_value.bytes[1] == 0x12)
printf("little ending");
else
printf("use test_value error");
return 0;
}
标签:blog io ar strong 数据 div sp on c
原文地址:http://www.cnblogs.com/notlate/p/3989146.html