大端(存储)模式,是指数据的低位保存在内存的高地址中,而数据的高位,保存在内存的低地址中;
小端(存储)模式,是指数据的低位保存在内存的低地址中,而数据的高位,,保存在内存的高地址中。
(1)
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<windows.h>
int Fun() {
int a = 0x12345678;
char* p = (char *)&a;
if (*p == 0x78) {
return 1;//小端
}
return 0;
}
int main() {
int ret = Fun();
if (ret == 1) {
printf("是小端!\n");
}
else {
printf("是大端!\n");
}
system("pause");
return 0;
}
(2)
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<windows.h>
int Fun1() {
union un {
short sh;
char ch;
}u;//从低地址开始共用内存
u.sh = 0x1234;
return u.ch;
}
int main() {
int ret = Fun1();
if (ret == 0x34) {
printf("是小端!\n");
}
else {
printf("是大端!\n");
}
system("pause");
return 0;
}