当前位置:网站首页>【秒杀概念】大小端
【秒杀概念】大小端
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。
边栏推荐
- Microwave oven rectifier diode cl01-12
- Selenium assertion and JS actuator
- What is the difference between request forwarding and request redirection?
- User defined variables and extracted public variables of JMeter
- Ssd7 | embedded friendly target detection network, product landing
- [RTOS training camp] program framework, preview, after-school homework and evening class questions
- Hcip day 13
- Regular expression
- 开放下载!《阿里巴巴 DevOps 实践手册》
- 测试左移和测试右移的概念
猜你喜欢

JDBC实现MySQL8.0数据库的增删改查

Microwave oven rectifier diode cl01-12

The task will be launched before the joint commissioning of development

用 QuestPDF操作生成PDF更快更高效!

Upload local file trial version using SAP ui5 fileuploader control

嵌入式开发:技巧和窍门——设计强大的引导加载程序的7个技巧

Travel + strategy accelerated landing, jietu new product matrix exposure

What is the difference between request forwarding and request redirection?

109. Upload local files using SAP ui5 fileuploader control

测试左移和测试右移的概念
随机推荐
The task will be launched before the joint commissioning of development
如何才能修炼成一名不可替代的程序员?
YOLOV3
参数解析器HandlerMethodArgumentResolver分析与实战
BGP comprehensive experiment
[RTOS training camp] GPIO knowledge and preview arrangement + evening class questions
With data-driven management transformation, the first year of science and technology was at the right time
[RTOS training camp] ring buffer, at instruction, preview arrangement and evening class questions
Leetcode notes 20. valid parentheses
Force deduction record: Sword finger offer (2) -- jz13-22
How to choose social e-commerce model in the early stage? Taishan crowdfunding
【软件开发规范四】《应用系统安全编码规范》
开放下载!《阿里巴巴 DevOps 实践手册》
Day06 MySql知识点总结
[install software after computer reset] software that can search all files of the computer, the best screenshot software in the world, free music player, JDK installation, MySQL installation, installa
Hnoi2012 mine construction
Data is written into excel and filled with color
Redis (VIII) - redis enterprises' actual coupons spike
[array creation in numpy]
JDBC实现MySQL8.0数据库的增删改查