当前位置:网站首页>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.
边栏推荐
猜你喜欢
P20 美颜相机的实现——基础铺垫2
文件IO实现图片的加密操作
P02 线程的用途
[Unity] GPU动画实现(二)——网格合并
[总结] Unity Lightmap使用总结
Industry Research: Analysis of the Status and Prospects of the Pension Insurance Market in 2022
神经网络的图像识别技术,神经网络的层数怎么看
【图形学】03 数学部分(三、各种变换矩阵)
Learning How to Ask: Querying LMs with Mixtures of Soft Prompts
Leetcode题目分享以及讲解
随机推荐
Leetcode题目分享以及讲解
C语言实现冒泡排序及对冒泡排序的优化处理
《Filter Pruning using Hierarchical Group Sparse》ICPR2020论文详解
必知必会的VGG网络(含代码)
【图形学】 06 四元数(一)
leetcode第84场双周赛
rhcsa第二天
Leetcode topic sharing and explanation
ESP32 温湿度和气体传感器驱动
SCIERC语料格式解读
C语言判断大小端存储问题
PURE(A Frustratingly Easy Approach for Entity and Relation Extraction)
最详细的Vivado安装教程
[总结] Unity Lightmap使用总结
ExecutionEngineException: String conversion error: Illegal byte sequence encounted in the input.
栈队列OJ题分享及讲解
Makefile文件的编写(实例详解)
P23 传值和传引用
C# Unicode (Universal Code) text conversion
【EagleEye】2020-ECCV-EagleEye: Fast Sub-net Evaluation for Efficient Neural Network Pruning-论文详解