当前位置:网站首页>C language judges the problem of big and small endian storage
C language judges the problem of big and small endian storage
2022-08-08 07:05:00 【night cat xu】
什么是大小端

小端存储:The low-order bits of the address store the low-order bits of the data.
大端存储:地址低位存数据高位.
方法一
使用C语言union来判断
#include <stdio.h>
union AA{
char a;
int b;
};
int main(int argc,const char * argv[])
{
union AA n;
n.b=0x12345678;
if(n.a==0x78)
{
printf("小端存储\n");//小端存储:The low-order bits of the address store the low-order bits of the data
}
else if(n.a==0x12)
{
printf("大端存储\n");//大端存储:地址低位存数据高位
}
return 0;
}
方法二
Use pointer coercion
#include <stdio.h>
int main(int argc,const char * argv[])
{
int a=0x12345678;
char *b=(char *)&a;
if(*b==0x78)
{
printf("小端存储\n");
}
else if(*b==0x12)
{
printf("大端存储\n");
}
}
The above are some simple methods for judging big and small endian storage.
边栏推荐
猜你喜欢
随机推荐
传统图像特征提取方法:边缘与角点
如何使用conda,pip安装、更新、查看和卸载重装Pytorch?
NVIDIA CUDA 高度并行处理器编程(六):并行模式:卷积
【图形学】15 UnityShader语义(三)
中序表达式转为后序表达式
C语言实现顺序表的九个常用接口
MongoDB3.x创建用户与用户角色
fpga卷积神经网络加速器,FPGA卷积神经网络综述
C# Unicode (Universal Code) text conversion
【图形学】09 UnityShader入门(一)
动手从零实现一个多层感知机(前馈神经网络)
Research analysis and development prospect forecast of electric shaver market status
Unity_预制体批量编辑器
PyTorch向量变换基本操作
rhcsa——第三天
神经网络和多元线性回归,神经网络多元线性回归
线性回归---Fit A Line
jupyter notebook添加目录
神经网络训练是什么意思,神经网络训练准确率
P03 线程安全 synchronized Lock









