当前位置:网站首页>大小端字节序
大小端字节序
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;
}

- 通常计算机都是使用小端字节序存储数据,而网络中的数据传输采用大端字节序
边栏推荐
- 记一次 .NET 某物管后台服务 卡死分析
- Detailed configuration of log4j
- Uni app develops wechat applet to dynamically render pages and dynamically change the order of page component modules
- 面试突击60:什么情况会导致 MySQL 索引失效?
- How to close windows defender Security Center
- Take stock of some easy-to-use and niche markdown editors
- Unlock the secret of C language key words (issue 6)
- 手把手带你入门 API 开发
- How to find the movie and TV clips with the same lines? These 8 movies search for artifact, and find the corresponding segment in one line
- 居家办公被催之后才明白的时间管理
猜你喜欢

picocli-入门

Industry insight - how should brand e-commerce reshape growth under the new retail format?

ACL 2022 | 中科院提出TAMT:TAMT:通过下游任务无关掩码训练搜索可迁移的BERT子网络

AI for Science:科研范式、开源平台和产业形态

Neo4j:入门基础(一)之安装与使用
![[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (II)](/img/ce/b58e436e739a96b3ba6d2d33cf8675.png)
[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (II)

How to participate in openharmony code contribution

Sorting out XXL job learning

script defer async模式

剑指 Offer 04. 二维数组中的查找
随机推荐
树莓派 3b+ 学习
剑指 Offer 04. 二维数组中的查找
浅谈珂朵莉树
[on Nacos] get started quickly
ACL 2022 | 中科院提出TAMT:TAMT:通过下游任务无关掩码训练搜索可迁移的BERT子网络
Topic38——56. Consolidation interval
esp32s3 IPERF例程测试 esp32s3吞吐量测试
How to participate in openharmony code contribution
ACL 2022 | TAMT proposed by Chinese Academy of Sciences: TAMT: search for a portable Bert subnet through downstream task independent mask training
xxl-job学习梳理
uni-app开发微信小程序动态渲染页面,动态改变页面组件模块顺序
Hands on API development
Neo4j: basic introduction (I) installation and use
今晚战码先锋润和赛道第2期直播丨如何参与OpenHarmony代码贡献
Mathematical knowledge -- ideas and examples of game theory (bash game, Nim game, wizov game)
动态规划【三】(区间dp)石子合并
build.gradle 配置
Sword finger offer 04 Find in 2D array
Introduce you to ldbc SNB, a powerful tool for database performance and scenario testing
What is the next step in the recommendation system? Alispacetime aggregates GNN, and the effect is to sling lightgcn!