当前位置:网站首页>大端模式和小端模式的区别
大端模式和小端模式的区别
2022-06-12 16:41:00 【icejuhua】
例如数据为0x01234567 内存中的存储地址为0x101 0x102 0x103 0x104其中0为符号位
大端模式:
大端模式是指数据的高位储存在内存中的低地址中,而数据的低位存储在内存的高地址中
小端模式:
小端模式是指数据的高位储存在内存中的高地址中,数据的低位存储在地址的低地址中,与小端模式相反
如下图所示:
| 内存地址 | 0x101 | 0x102 | 0x103 | 0x104 |
| 大端模式 | 01 | 23 | 45 | 67 |
| 小端模式 | 67 | 45 | 23 | 01 |
大小端模式的适用情况:
大小端模式使用的情况主要式看使用的单片机支持什么样的模式,按照不同的机子选择不同的模式才是正确的使用方法
eg:大端模式:KEIL C51
小端模式:很多的ARM,DSP都是使用小端模式(更普遍)
还有的单片机可以选择使用不同的模式
为什么会有大小端模式的不同
这是因为在计算机系统中,我们是以字节为单位的,每个地址单元都对应着一个字节,一个字节为8bit。但是在C语言中除了8bit的char之外,还有16bit的short型,32bit的long型(要看具体的编译器和系统环境),另外,对于位数大于8位的处理器,例如16位或者32位的处理器,由于寄存器宽度大于一个字节,那么必然存在着一个如果将多个字节安排的问题。因此就导致了大端存储模式和小端存储模式。例如一个16bit的short型x,在内存中的地址为0x0010,x的值为0x1122,那么0x11为高字节,0x22为低字节。对于大端模式,就将0x11放在低地址中,即0x0010中,0x22放在高地址中,即0x0011中。小端模式,刚好相反。我们常用的X86结构是小端模式,而KEIL C51则为大端模式。很多的ARM,DSP都为小端模式。有些ARM处理器还可以由硬件来选择是大端模式还是小端模式。
最后再讲一下优点缺点
大小端模式其实没有所谓的优点缺点
小端模式:在进行强制转换的时候数据不会出错,因为是按照内存递增而从小到大存储数据的
大端模式:由于最高位是符号位,所以判断符号比较容易
边栏推荐
- [BSP video tutorial] BSP video tutorial issue 17: single chip microcomputer bootloader topic, startup, jump configuration and various usage of debugging and downloading (2022-06-10)
- pbootcms的if判断失效直接显示标签怎么回事?
- MySQL面试整理
- calibration of sth
- MySQL statement
- Latex table online generation
- CVPR 2022 | 元学习在图像回归任务的表现
- Glove word embedding (IMDb film review emotion prediction project practice)
- 使用ubantu时,遇见的一些小毛病和解决方法
- [Hunan University] information sharing of the first and second postgraduate entrance examinations
猜你喜欢

Idea how to set the guide package without * sign

canvas 高级功能(下)

使用ubantu时,遇见的一些小毛病和解决方法

博士申請 | 新加坡國立大學Xinchao Wang老師招收圖神經網絡方向博士/博後

叶子分享站PHP源码下载

【研究】英文论文阅读——英语poor的研究人员的福利

Collect | 22 short videos to learn Adobe Illustrator paper graphic editing and typesetting

男神女神投票源码 v5.5.21 投票源码

Recommend AI intelligent drawing repair software

su直接切换到超级管理员模式,这样很多报错都可以避免了
随机推荐
薛定谔的日语学习小程序源码
[MySQL] internal connection, external connection and self connection (detailed explanation)
Mongodb learning and sorting (basic command learning of users, databases, collections and documents)
\begin{algorithm} 笔记
\Begin{algorithm} notes
token与幂等性问题
[Hunan University] information sharing of the first and second postgraduate entrance examinations
[adult Liu Er - pytorch deep learning practice] notes with learning (I)
Analysis of Nacos config dynamic refresh source code
Anfulai embedded weekly report no. 268: May 30, 2022 to June 5, 2022
calibration of sth
canvas 处理图像(上)
博士申请 | 新加坡国立大学Xinchao Wang老师招收图神经网络方向博士/博后
Learning notes of MySQL series by database and table
redis.clients.jedis.exceptions.JedisDataException: NOAUTH Authentication required
The C programming language (version 2) notes / 8 UNIX system interface / 8.1 file descriptor
Loading shellcode in C and go languages
QCustomplot笔记(一)之QCustomplot添加数据以及曲线
【BSP视频教程】BSP视频教程第17期:单片机bootloader专题,启动,跳转配置和调试下载的各种用法(2022-06-10)
calibration of sth