当前位置:网站首页>【秒杀概念】大小端
【秒杀概念】大小端
2022-07-26 00:43:00 【粉墨白伶】
目录
秒杀概念,编程如此简单!快点击订阅吧!
示例
int a = 20;
int b = -10;
按照“原反补”的法则,我们可以推出它们在内存中的补码
int 是 4 个字节那就有 32 个 bit 位
加粗的二进制位就是符号位
int a = 20(正数)
原 //2^2 + 2^4 = 4 + 16 = 20
0000 0000 0000 0000 0000 0000 0001 0100
反
0000 0000 0000 0000 0000 0000 0001 0100
补
0000 0000 0000 0000 0000 0000 0001 0100
int b = -10(负数)
原 // -(2^1 + 2^3) = -(2 + 8) = -10
1000 0000 0000 0000 0000 0000 0000 1010
反 //符号位不变,其他位按位取反
1111 11111 11111 1111 1111 1111 1111 0101
补 //反码+1
1111 11111 1111 11111 1111 1111 1111 0110
因位在内存的存储是十六进制的所以要进行转化
十六进制是以 4 个 bit 位为单位进行转化的
因为 4 个 bit 位刚好可以表示范围在 [0, 2^4) 的数
a
二进制补码
0000 0000 0000 0000 0000 0000 0001 0100
转化为十六进制
00 00 00 14
b
二进制补码
11111 1111 1111 1111 1111 1111 1111 0110
转化为十六进制
f f f f f f f 6
然后我们可以在编译器调试后的内存窗口中输入 &a, &b 观察是否正确:

我们发现 a 是 14 00 00 00,b 是 f6 ff ff ff ,好像和我们推测的不一样,这是因为内存的存储有两种模式,分为大端(存储)模式,小端(存储)模式;
什么是大端小端?
大端(存储)模式
指数据的低位保存在内存的高地址中,而数据的高位,保存在内存的低地址中;
小端(存储)模式
指数据的低位保存在内存的低地址中,而数据的高位,保存在内存的高地址中。
我们之前通过“原反补”推出的 a 00 00 00 14 和 b ff ff ff f6 中,数据的高位在左边,低位就在右边,
然后我们将内存窗口的显示调成 1 列

我们可以看到内存 1 中的地址是从 0x003DF918 增加到 0x003DF91B ,所以上面是低地址,下面是高地址。这样我们就发现数据的低位保存在内存的低地址中,而数据的高位,保存在内存的高地址中,所以我们当前编译器的存储模式就为小端存储模式。这就是为什么我们看到的是 14 00 00 00 而不是 00 00 00 14。
边栏推荐
- 旅行+战略加速落地 捷途新产品矩阵曝光
- If the native family is general, and the school is also a college on the rotten street, how to go on the next journey
- [GOM engine] script setting method for dummy configuration
- Redis Command Reference Manual - key
- Tarjan finds the strongly connected component o (n+m), shrinking point
- The task will be launched before the joint commissioning of development
- Nanjie's embarrassment
- 测试左移和测试右移的概念
- [RTOS training camp] continue the program framework, tick interrupt supplement, preview, after-school homework and evening class questions
- Jmeter之用户自定义变量和抽离公共变量
猜你喜欢

AI knows everything: build and deploy sign language recognition system from 0

Lock upgrade: no lock, bias lock, lightweight lock, heavyweight lock

How to choose social e-commerce model in the early stage? Taishan crowdfunding

【软件开发规范三】【软件版本命名规范】

YOLOV2 YOLO9000

开放下载!《阿里巴巴 DevOps 实践手册》

Travel + strategy accelerated landing, jietu new product matrix exposure

JDBC implements the addition, deletion, modification and query of MySQL 8.0 database

【RTOS训练营】设备子系统、晚课学员提问

进程与线程
随机推荐
【RTOS训练营】环形缓冲区、AT指令、预习安排和晚课提问
2022/7/25 exam summary
El table scroll bar settings
使用 SAP UI5 FileUploader 控件上传本地文件试读版
How jupyter changes the default browser
[array creation in numpy]
以数据驱动管理转型,元年科技正当时
HCIP第十三天
Hcip day 13
jupyter更改主界面并且导入数据集
Zabbix监控主机及资源告警
With data-driven management transformation, the first year of science and technology was at the right time
Force deduction record: Sword finger offer (2) -- jz13-22
Test the concept of left shift and right shift
Django database addition, deletion, modification and query
Unityvr -- robot arm scene 4- gifts and Christmas tree
什么是信息化?什么是数字化?这两者有什么联系和区别?
Tell you the meaning of unit testing from another angle
Tarjan finds the strongly connected component o (n+m), shrinking point
Set set learning