当前位置:网站首页>大端模式和小端模式的区别
大端模式和小端模式的区别
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处理器还可以由硬件来选择是大端模式还是小端模式。
最后再讲一下优点缺点
大小端模式其实没有所谓的优点缺点
小端模式:在进行强制转换的时候数据不会出错,因为是按照内存递增而从小到大存储数据的
大端模式:由于最高位是符号位,所以判断符号比较容易
边栏推荐
- 使用ubantu时,遇见的一些小毛病和解决方法
- Why is your next computer a computer? Explore different remote operations
- Gopher to rust hot eye grammar ranking
- Project training of Shandong University rendering engine system (VI)
- key为断言的map是怎么玩的
- mysql语句
- [MySQL] internal connection, external connection and self connection (detailed explanation)
- Token and idempotency
- 《安富莱嵌入式周报》第268期:2022.05.30--2022.06.05
- The C programming language (version 2) notes / 8 UNIX system interfaces / 8.6 instances (directory list)
猜你喜欢

Idea how to set the guide package without * sign

薛定谔的日语学习小程序源码

Cookies and sessions

Project training of Shandong University rendering engine system (III)

Which colleges are particularly easy to enter?

Recommend 6 open source projects of yyds

idea如何设置导包不带*号

CVPR 2022 | meta learning performance in image regression task

su直接切换到超级管理员模式,这样很多报错都可以避免了
![[MySQL] Cartesian product - multi table query (detailed explanation)](/img/46/6a9a62b35eaa538232da1d738b3931.jpg)
[MySQL] Cartesian product - multi table query (detailed explanation)
随机推荐
Cookie 和 Session
Project training of Shandong University rendering engine system (IV)
js监听用户是否打开屏幕焦点
"Shandong University project training" rendering engine system (8-END)
Probation period and overtime compensation -- knowledge before and after entering the factory labor law
双写一致性问题
收藏 | 22个短视频学习Adobe Illustrator论文图形编辑和排版
canvas 高级功能(下)
1.delete
Project training of Shandong University rendering engine system (VI)
Overview of webrtc's audio network Countermeasures
2022-2028 global press dehydrator industry research and trend analysis report
Qcustomplot notes (I): qcustomplot adding data and curves
Possible problems of long jump in gaussdb
js監聽用戶是否打開屏幕焦點
CVPR 2022 | 元学习在图像回归任务的表现
超详细干货!Docker+PXC+Haproxy搭建高可用强一致性的MySQL集群
ISCC-2022 部分wp
Loading shellcode in C and go languages
[raspberry pie]: (IV) camera advanced