当前位置:网站首页>大小端字节序
大小端字节序
2022-06-27 12:17:00 【xiongsiyu979】
一、什么是大小端字节序
数据高位:例如16进制数0x123456789,0x12就是数据高位,相对,0x89就是数据低位
高地址空间:例如下面的地址0x00000002就是高位地址空间,相对,地址0x00000001就是低位地址空间
小端字节序(LSB):将数据的高位存储在高地址空间
大端字节序(HSB):将数据的高位存储在低地址空间
总结:小端顺序,大端逆序
- 顺序是指数据高低位序和地址的高低序是同一个方向
- 逆序是指数据高低位序和地址的高低序是相反的方向
二、代码测试
- 不同的cpu(大小端是由cpu决定的)在存储数据的时候会有不同的策略:
- 用下面的代码来判断计算机是采用了什么字节序
#include <stdio.h>
int main()
{
int a = 0x12345678;
char *b = (char *)&a;//使用char类型指针是希望取值只取1Byte
if(*b == 0x12)
printf("大端\n");
else if(*b == 0x78)
printf("小端\n");
return 0;
}
- 通常计算机都是使用小端字节序存储数据,而网络中的数据传输采用大端字节序
边栏推荐
- log4j. Detailed configuration of properties
- Picocli getting started
- esp32s3 IPERF例程测试 esp32s3吞吐量测试
- 推荐系统的下一步?阿里时空聚合GNN,效果吊打LightGCN!
- Three traversal methods of binary tree
- uni-app开发微信小程序动态渲染页面,动态改变页面组件模块顺序
- Uniapp drop-down layer selection box effect demo (sorting)
- Topic37——64. Minimum path sum
- Neo4j: basic introduction (I) installation and use
- DM8:达梦数据库-锁超时
猜你喜欢
Sorting out XXL job learning
Nmcli team bridge basic configuration
行业洞察 | 新零售业态下,品牌电商应如何重塑增长?
动态规划【三】(区间dp)石子合并
Interview shock 60: what will cause MySQL index invalidation?
Private dry goods sharing: how to implement platform in Enterprise Architecture
让学指针变得更简单(二)
阿里一个面试题:使用两个线程,交替输出字母和数字
推荐系统的下一步?阿里时空聚合GNN,效果吊打LightGCN!
解开C语言的秘密《关键字》(第六期)
随机推荐
Review summary of database
Comment modifier Node Fichiers dans les modules
ssh服务器配置文件sshd_config 及操作
Steps for win10 to completely and permanently turn off automatic updates
MySQL learning 1: installing MySQL
esp32s3 IPERF例程测试 esp32s3吞吐量测试
如何修改 node_modules 裏的文件
mybaitis生成器详解
解开C语言的秘密《关键字》(第六期)
Unlock the secret of C language key words (issue 6)
[fans' welfare] today, I'd like to introduce a method to collect money for nothing - convertible bonds. I personally verified that each person can earn 1500 yuan a year
居家办公被催之后才明白的时间管理
Uniapp drop-down layer selection box effect demo (sorting)
深入理解 happens-before 原则
微服务之配置管理中心
Picocli getting started
全球最强截图软件 Snipaste
浏览器输入url地址,到页面渲染发生了什么
Hibernate operation Oracle database primary key auto increment
It is so simple to remove the payment restrictions on VIP, YuQue and Zhihu in Baidu Library