当前位置:网站首页>大端模式和小端模式的區別
大端模式和小端模式的區別
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處理器還可以由硬件來選擇是大端模式還是小端模式。
最後再講一下優點缺點
大小端模式其實沒有所謂的優點缺點
小端模式:在進行强制轉換的時候數據不會出錯,因為是按照內存遞增而從小到大存儲數據的
大端模式:由於最高比特是符號比特,所以判斷符號比較容易
边栏推荐
- Collect | 22 short videos to learn Adobe Illustrator paper graphic editing and typesetting
- Qt开发高级进阶:初探qt + opengl
- 数据库的三大范式
- The C programming language (version 2) notes / 8 UNIX system interface / 8.1 file descriptor
- The safety of link 01 was questioned, and "ultra high strength" became "high strength"_ Publicity_ Steel_ problem
- latex表格 在线生成
- Google browser debugging skills
- QCustomplot笔记(一)之QCustomplot添加数据以及曲线
- MySQL面试整理
- 【研究】英文论文阅读——英语poor的研究人员的福利
猜你喜欢

云开发坤坤鸡乐盒微信小程序源码

叶子分享站PHP源码下载

Extract the new Chinese cross modal benchmark zero from 5billion pictures and texts, and Qihoo 360's new pre training framework surpasses many SOTAS

pytorch和torchvision官方文档使用方法

JVM memory model and local memory

JVM内存模型与本地内存

Recommend AI intelligent drawing repair software

Large scale real-time quantile calculation -- a brief history of quantitative sketches

如何基于CCS_V11新建TMS320F28035的工程

Uniapp壁纸小程序源码/双端微信抖音小程序源码
随机推荐
从50亿图文中提取中文跨模态新基准Zero,奇虎360全新预训练框架超越多项SOTA
Token and idempotency
Probation period and overtime compensation -- knowledge before and after entering the factory labor law
Leetcode 2190. The number that appears most frequently in the array immediately after the key (yes, once)
\Begin{algorithm} notes
Unit sshd.service could not be found
VIM from dislike to dependence (16) -- macro
h t fad fdads
CAS乐观锁
QCustomplot笔记(一)之QCustomplot添加数据以及曲线
About component value transfer
Structural requirement analysis of software engineering student information management system
mysql语句
软件工程 学生信息管理系统 结构化的需求分析
What's the matter with pbootcms' if judgment failure and direct display of labels?
Double write consistency problem
34- [go] golang channel knowledge points
STL -- function object
The C programming language (version 2) notes / 8 UNIX system interface / 8.7 instance (storage allocator)
博士申请 | 新加坡国立大学Xinchao Wang老师招收图神经网络方向博士/博后