当前位置:网站首页>大端模式和小端模式的区别
大端模式和小端模式的区别
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处理器还可以由硬件来选择是大端模式还是小端模式。
最后再讲一下优点缺点
大小端模式其实没有所谓的优点缺点
小端模式:在进行强制转换的时候数据不会出错,因为是按照内存递增而从小到大存储数据的
大端模式:由于最高位是符号位,所以判断符号比较容易
边栏推荐
- Leetcode 2190. 数组中紧跟 key 之后出现最频繁的数字(可以,一次过)
- 云开发坤坤鸡乐盒微信小程序源码
- Leetcode 2190. The number that appears most frequently in the array immediately after the key (yes, once)
- std::set compare
- The C programming language (version 2) notes / 8 UNIX system interface / 8.4 random access (lseek)
- 图片在线收款发货系统源码
- Object. Keys traverses an object
- 程序员爆料:4年3次跳槽,薪资翻了3倍!网友:拳头硬了......
- [adult Liu Er - pytorch deep learning practice] notes with learning (I)
- Golang recursively encrypts and decrypts all files under the specified folder
猜你喜欢

Leetcode 2194. Excel 表中某个范围内的单元格(可以,已解决)
![[MySQL] Cartesian product - multi table query (detailed explanation)](/img/46/6a9a62b35eaa538232da1d738b3931.jpg)
[MySQL] Cartesian product - multi table query (detailed explanation)

Idea displays services on the console to uniformly manage all jetty services,

MongoDB 学习整理(用户,数据库,集合,文档 的基础命令学习)
![[MySQL] internal connection, external connection and self connection (detailed explanation)](/img/3f/9b88c2f27455f2ddd73808fbb44f8e.jpg)
[MySQL] internal connection, external connection and self connection (detailed explanation)

IDEA在控制台显示出services,统一管理所有的jetty服务,

Leetcode 2194. Excel 錶中某個範圍內的單元格(可以,已解决)

【湖南大学】考研初试复试资料分享

How to play the map with key as assertion

Swin Transformer代码讲解
随机推荐
Leetcode 2190. The number that appears most frequently in the array immediately after the key (yes, once)
Object. Keys traverses an object
Qcustomplot notes (I): qcustomplot adding data and curves
CAS乐观锁
redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
Leetcode 2194. Cellules dans une plage dans un tableau Excel (OK, résolu)
Leetcode 2194. Excel 表中某个范围内的单元格(可以,已解决)
su直接切换到超级管理员模式,这样很多报错都可以避免了
Daily question -890 Find and replace mode
890. find and replace mode / Sword finger offer II 080 Combination with k elements
The C programming language (version 2) notes / 8 UNIX system interface / 8.5 instance (implementation of fopen and Getc functions)
Overview of webrtc's audio network Countermeasures
How to play the map with key as assertion
calibration of sth
Understand go modules' go Mod and go sum
MongoDB 学习整理(用户,数据库,集合,文档 的基础命令学习)
Idea displays services on the console to uniformly manage all jetty services,
generate pivot data 1
VIM from dislike to dependence (16) -- macro
Servlet API