当前位置:网站首页>Two methods to judge the storage of large and small end
Two methods to judge the storage of large and small end
2022-06-11 21:54:00 【Code loving students】
1. Coercive transformation
Given int Variable of type a, The assignment is 1,1 Of 16 Into the system for :00 00 00 01.
If the small end stores a Stored as :01 00 00 00.
Big end storage is :00 00 00 01.
You can take out a Your address is forced to char* type ,*(char*)&a To judge the value as 0/1.
If it is 0 It is big end storage , yes 1 Store for small end .
The code implementation is as follows :
int main()
{
int a = 1;
//00 00 00 01
if (*(char*)&a == 1)
printf(" Small end storage \n");
else
printf(" Big end storage \n");
return 0;
}2. Using Commons
Pictured :

We can find out a,b The address of is the same , So for b Changes , Will also change a. because b Occupy four bytes , and a There is only one byte .

In the case of small end storage c In Chinese, it means 1,
On the contrary, if it is large-end storage, then c In Chinese, it means 0.
The code implementation is as follows :
typedef union A
{
char a;
int b;
}A;
int main()
{
A a;
a.b = 1;
if (a.a == 1)
printf(" Small end storage \n");
else
printf(" Big end storage \n");
}边栏推荐
- 建造者模式
- 联调这夜,我把同事打了...
- 类和对象(2)
- Classes and objects (1)
- Example of using zypper command
- The upcoming launch of the industry's first retail digital innovation white paper unlocks the secret of full link digital success
- Collection of articles and literatures related to R language (continuously updated)
- [academic related] under the application review system, how difficult is it to study for a doctoral degree in a double first-class university?
- Rexroth overflow valve zdb6vp2-42/315v
- Uncover the secret of the popular app. Why is it so black
猜你喜欢

联调这夜,我把同事打了...

Introduction à endnotex9 et instructions pour les tutoriels de base

In the post epidemic era, how can enterprise CIOs improve enterprise production efficiency through distance

EndnoteX9簡介及基本教程使用說明

Classes and objects (2)

Popular science | what are the types of NFT (Part 1)

Leetcode-98- validate binary search tree

RPA super automation | nongnongji and cloud expansion accelerate financial intelligent operation

Add anti debugging function to game or code (application level)

JVM | runtime data area; Program counter (PC register);
随机推荐
每日一题 - 罗马数字转整数
Example of using zypper command
JVM | local method interface; Native Method Stack
R语言相关文章、文献整理合集(持续更新)
Collection of articles and literatures related to R language (continuously updated)
servlet获取表单数据
Redis Foundation
The network connection is normal, but Baidu web page can not be opened and displayed. You can't access this website solution
Leetcode-104- maximum depth of binary tree
BZOJ3189 : [Coci2011] Slika
如何查看win系统的安装日期
Codeforces Round #742 (Div. 2) F. One-Four Overload
238.除自身以外数组的乘积
189. 轮转数组
Codeworks round 739 (Div. 3) problem solving Report
二分查找 - 学习
「大模型」之所短,「知识图谱」之所长
Top - k问题
Leetcode-110-balanced binary tree
类和对象(1)