当前位置:网站首页>怎么判断大小端(网络字节序和主机字节序)
怎么判断大小端(网络字节序和主机字节序)
2022-07-30 05:39:00 【m~~?】
怎么判断大小端(网络字节序和主机字节序)
判断方式
使用union进行判断,这里说一下能用union判断的理由,union所占的字节数是union中成员的最大字节数,也就是说成员们共用同一块地址。
#include<stdio.h>
void byteOrder() {
union {
short data;
char value[2];
}test;
test.data = 0x0102;
if (test.value[0] == 1 && test.value[1] == 2) //低位高地址
printf("big endian\n");
else if (test.value[0] == 2 && test.value[1] == 1) //低位低地址
printf("little endian\n");
else
printf("oo\n");
}
int main() {
byteOrder();
return 0;
}
参考游双老师
边栏推荐
- ClickHouse 数据插入、更新与删除操作 SQL
- k折交叉验证(k-fold Cross-validation)
- This dependency was not found:
- The difference between asyncawait and promise
- [Image processing] Image skeleton extraction based on central axis transformation with matlab code
- Countdown (Source: Google Kickstart2020 Round C Problem A) (DAY 88)
- 条件变量解决生产者消费者问题
- cJSON开源项目详细解剖
- union中有struct的情况-从内存分析
- MySQL笔记(pymysql)
猜你喜欢
随机推荐
list(列表)和array(数组)的区别
报错:npm ERR code EPERM
Qt实现一个重复文件检测小工具(原理:通过md5校验)
【线性神经网络】线性回归 / 基础优化方法
“tensorflow.keras.preprocessing“ has no attribute “image_dataset_from_directory“
微积分 / 自动求导
ClickHouse data insert, update and delete operations SQL
MySQL的 DDL和DML和DQL的基本语法
Graphic mirror symmetry (schematic diagram)
多进程实现并发服务器
cnpm installation steps
pytorch中的线性代数
Teach you how to design a CSDN system
Learn FPGA from the underlying structure (6) ---- Distributed RAM (DRAM, Distributed RAM)
Record Breaker (Google Kickstart2020 Round D Problem A)
optimizer.zero_grad()
524.通过删除字母匹配到字典里最长单词
flask使用token认证
Falling ants (Peking University entrance exam questions)
Qt实现单击或双击QTableWidge/View表头进行排序









