当前位置:网站首页>怎么判断大小端(网络字节序和主机字节序)
怎么判断大小端(网络字节序和主机字节序)
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;
}
参考游双老师
边栏推荐
猜你喜欢
More fragrant open source projects than Ruoyi in 2022
ezTrack-master使用教程
646.最长数对链(动态规划)
[GO Language Basics] 1. Why do I want to learn Golang and the popularization of GO language entry
MySQL fuzzy query performance optimization
MySQL模糊查询性能优化
navicat无法连接mysql超详细处理方法
Qt对动态库(*.dll)的封装以及使用
[Image processing] Image skeleton extraction based on central axis transformation with matlab code
MySQL stored procedure
随机推荐
人生的第一篇博客(初识代码)
5.6EPOLLONESHOT事件
ClickHouse 数据插入、更新与删除操作 SQL
871.最低加油次数(动态规划)
海量号码需要保存,如何才能尽可能少地占用内存?
初识C语言
C语言:快速排序三种方法(递归)
[Mysql] DATEDIFF function
安装Nuxt.js时出现错误:TypeError:Cannot read property ‘eslint‘ of undefined
【线性神经网络】线性回归 / 基础优化方法
C语言人机大战之三字棋博弈
union中有struct的情况-从内存分析
Qt在QTableWidget、View等表格中添加右击菜单
Memories · The last system design in the university era
HCIP-第九天-BGP(边界网关协议)
互斥量解决线程同步问题
MySql的初识感悟,以及sql语句中的DDL和DML和DQL的基本语法
操作系统面试整理
安装pytorch
Teach you how to design a CSDN system