大端模式:高字節放低地址,低字節放高地址
小端模式:高字節放高地址,低字節放低地址
一個數0x1234中0x12位高字節,0x34爲低字節。
51單片機:大端模式
80x86微機:小端模式
STM32:小端模式
以下是測試大小端模式的程序,主要是利用了聯合體結構中的成員共享一個存儲空間:
#include <stdio.h>
void main(void)
{
union data
{
int i;
char c;
}test;
test.i=0x1234;
if(test.c==0x12)
{
printf("Big-endian\n");
}
else if(test.c==0x34)
{
printf("Little-endian\n");
}
else
{
printf("error!\n");
}
}
在PC機上運行結果: