当前位置:网站首页>C language judging big end and small end [consortium or pointer] big end and small end conversion
C language judging big end and small end [consortium or pointer] big end and small end conversion
2022-06-11 07:26:00 【Nwafu_ zyccc】
#include <io_utils.h>
int IsBigEndian() {
union {
char c[2];
short s;
} value = {
.s=0x100};
return value.c[0] == 1;
}
int IsBigEndian2() {
short s = 0x100;
char *p = (char *)&s;
return p[0] == 1;
}
int ToggleEndian(int original) {
union {
char c[4];
int i;
} value = {
.i=original};
char temp = value.c[0];
value.c[0] = value.c[3];
value.c[3] = temp;
temp = value.c[1];
value.c[1] = value.c[2];
value.c[2] = temp;
return value.i;
}
int ToggleEndian2(int original) {
char *p = (char *)&original;
char temp = p[0];
p[0] = p[3];
p[3] = temp;
temp = p[1];
p[1] = p[2];
p[2] = temp;
return original;
}
int main() {
PRINT_INT(IsBigEndian());
int original = 0x12345678;
PRINT_HEX(ToggleEndian(original));
return 0;
}
边栏推荐
猜你喜欢
![pycharm出现error.DeprecatedEnv: Env FrozenLake-v0 not found (valid versions include [‘FrozenLake-v1‘])](/img/1c/4013479ce1fc5b0ff2ebeb754f05a9.png)
pycharm出现error.DeprecatedEnv: Env FrozenLake-v0 not found (valid versions include [‘FrozenLake-v1‘])

Several transaction modes of Seata

May 30-June 5, 2022 AI industry weekly (issue 100): three years
![[并发进阶]——线程池总结](/img/69/dc8146dafc30f8a8efa012b67aa05c.png)
[并发进阶]——线程池总结
![[analysis of STL source code] summary note (4): behind the scenes hero allocator](/img/b9/cf53fd8f933042ff65844d61eca55e.jpg)
[analysis of STL source code] summary note (4): behind the scenes hero allocator

学 SQL 必须了解的10个高级概念

2、 User login and registration

No response from win10 explorer when dragging files

Mistakes in Niuke JS exercise

big. Js-- use / instance
随机推荐
【CF#697 (Div. 3)】 A - Odd Divisor
Nosqlzoo question brushing-1
The gap between the parent box and the child box
P5431 [template] multiplicative inverse 2
【CF#262 (Div. 2)】 A. Vasya and Socks
337. house raiding III
[并发进阶]——线程池总结
Summary of classic interview questions
农房一体脚本的心得记录
big. Js-- use / instance
Dynamically change the direction of this
Library management system 1- project approval
213. house raiding II
JVM学习记录(七)——类加载过程与双亲委派模型
es5和es6的学习小记
A case in which the MySQL administrator password cannot take effect
**Count the characters with the largest number of words**
The rotation of the earth and the moon (II)
Oracle pl/sql these query results cannot be updated. Please include ROWID or use Select For update
Android and IOS reverse analysis / security detection / penetration testing framework