当前位置:网站首页>大端模式和小端模式的區別
大端模式和小端模式的區別
2022-06-12 16:53: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處理器還可以由硬件來選擇是大端模式還是小端模式。
最後再講一下優點缺點
大小端模式其實沒有所謂的優點缺點
小端模式:在進行强制轉換的時候數據不會出錯,因為是按照內存遞增而從小到大存儲數據的
大端模式:由於最高比特是符號比特,所以判斷符號比較容易
边栏推荐
- JVM memory model and local memory
- WebRTC 的音频网络对抗概述
- [adult Liu Er - pytorch deep learning practice] notes with learning (I)
- goland变成中文版了怎么修改回英文版
- Demande de doctorat | xinchao Wang, Université nationale de Singapour
- Loading shellcode in C and go languages
- JS using RSA encryption and decryption
- 启牛开的证券账户安全吗?合法吗?
- Canvas image processing (Part 1)
- canvas 处理图像(上)
猜你喜欢

How to play the map with key as assertion

Unit sshd. service could not be found

What's the matter with pbootcms' if judgment failure and direct display of labels?

Programmers broke the news: 3 job hopping in 4 years, and the salary has tripled! Netizen: the fist is hard

Leetcode 2190. 数组中紧跟 key 之后出现最频繁的数字(可以,一次过)

How to base on CCS_ V11 new tms320f28035 project

修改自己电脑连接的路由器的配置网址192.168.1.1

canvas 高级功能(下)

Iscc-2022 part WP
![[MySQL] internal connection, external connection and self connection (detailed explanation)](/img/3f/9b88c2f27455f2ddd73808fbb44f8e.jpg)
[MySQL] internal connection, external connection and self connection (detailed explanation)
随机推荐
h t fad fdads
Programmers broke the news: 3 job hopping in 4 years, and the salary has tripled! Netizen: the fist is hard
Latex table online generation
ISCC-2022 部分wp
Cookies and sessions
怎么在公司里面做好测试工作(做好测试工作)
\Begin{algorithm} notes
并发包和AQS
\Begin{algorithm} notes
redis.clients.jedis.exceptions.JedisDataException: NOAUTH Authentication required
修改自己电脑连接的路由器的配置网址192.168.1.1
Leetcode 2190. The number that appears most frequently in the array immediately after the key (yes, once)
Which colleges are particularly easy to enter?
How to play the map with key as assertion
How to do a good job of testing in the company (do a good job of testing)
Collect | 22 short videos to learn Adobe Illustrator paper graphic editing and typesetting
从50亿图文中提取中文跨模态新基准Zero,奇虎360全新预训练框架超越多项SOTA
js监听用户是否打开屏幕焦点
Project training of Shandong University rendering engine system (VI)
软件工程 学生信息管理系统 结构化的需求分析