1.引言
计算机和嵌入式产品中数据的存储方式分为大端和小端两种方式。为什么呢?因为对于大多数设备都需要存储超过1个字节的数据单元。比如,你要表达0x12345678这个数字。使用1个字节的存储空间是肯定完成不了的。因此,你必须使用4个字节的空间才能够把这个数存放在设备。
2. 图解大小端

小端模式就是数据的高有效位放在高地址,低有效位放在低地址上。
大端模式就是数据的高有效位放在低地址,低有效位放在高地址上。
3.测试运行程序的计算机是大端还是小端
文件名:endian.cpp
#include<iostream>
typedef unsigned int uint32;
typedef unsigned char uint8;
int main(int argn, char* argv[])
{
    uint32 tmp = 0x12345678;
    if(*(uint8*)&tmp == 0x78)
    {
        std::cout << "This computer is little endian" << std::endl;
    }
    else if(*(uint8*)&tmp == 0x12)
    {
        std::cout << "This computer is big endian" << std::endl;
    }
    else
    {
        std::cout << " happen err " << std::endl;
    }
    return 0;
}Makefile
TGT := app
OPTION := -I.
SRC = endian.cpp
all:$(TGT)
	@echo "Make successfull!"
$(TGT):$(SRC)
	g++ -std=c++11 $(OPTION) $^ -o $@
clean:
	rm $(TGT)
.PHONY: all clean运行结果
xuehy@ubuntu:/mnt/99_github/cpp_demo$ make
g++ -std=c++11 -I. endian.cpp -o app
Make successfull!
xuehy@ubuntu:/mnt/99_github/cpp_demo$ ./app 
This computer is little endian
xuehy@ubuntu:/mnt/99_github/cpp_demo$ 
结论:运行此程序的计算机是小端。












![[2021最新]大数据平台CDH存储组件kudu之启用HA高可用(添加多个master)](https://img-blog.csdnimg.cn/2021041515491117.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ0NDkxNzA5,size_16,color_FFFFFF,t_70)






