当前位置:网站首页>Signed and unsigned keywords
Signed and unsigned keywords
2022-07-06 22:30:00 【It's Beichen not too PI acridine】
signed、unsigned keyword
We know that the bottom of the computer only knows 0、1. Any data at the bottom will be converted into 0、1. How to store negative numbers ? I'm sure this “-” The number cannot be stored in memory , What do I do ? It's easy to do , Make a mark . Free up the highest bit of the basic data type , Used to store symbols , At the same time, it is agreed as follows : If the highest order is 1, Indicates that this number is negative , The value is added to the value of the remaining bits except the highest bit “-” Number ; If the highest level is 0, Indicates that this number is a positive number , Its value is the value of the remaining bits except the highest bit .

int main()
{
char a[1000];
int i;
for(i=0; i<1000; i++)
{
a[i] = -1-i;
}
printf("%d",strlen(a));
return 0;
}
To do this problem, we must first consider two problems
1. How are values saved on the computer . In computer system , All values are represented by complements ( Storage )
2. How to save after overflow . There was an overflow ,-129 need 9 Bits can be stored , and char The type data is only 8 position , So the highest bit is discarded .
Also understand the conversion between the original code and the complement 
Here are some steps to solve the problem 


1. answer :
hypothesis +0 and -0 All are int data .int Type data size is 4Byte = 32 bit
We know , Integer data stored in memory is binary complement .
2. answer :
If you press %d Output is -10; Press %u The output is a large value .
The calculated complement is then converted into the original code 
In unsigned integer form (%u) Output
The complement obtained above is the same , The original code is also this , Just for %u When outputting , The highest bit is not the sign bit , Instead, it becomes a numerical digit , So it becomes a big number .
3. answer :
Defines an unsigned integer variable i, We know that unsigned numbers are always greater than or equal to 0, therefore i>=0 Your judgment has always been true . The program execution will be endless .
In specific cases, we can still use complement ,. We know -1 The complement of is 32 individual 1,i Shaping for unsigned , So its corresponding 10 Decimal digits :2^32 -1 =4294967295. So the running result of the program is :9,8, 7, 6,5,4, 3,2, 1,0,4294967295,4294967294 …
Let's test it
#include<stdio.h>
#include<Windows.h>
int main()
{
unsigned i;
for (i = 9; i >= 0; i--)
{
printf("%u\n", i);
Sleep(1000);
}
return 0;
}

边栏推荐
- Data processing skills (7): MATLAB reads the data in the text file TXT with mixed digital strings
- Assembly and interface technology experiment 5-8259 interrupt experiment
- UE4蓝图学习篇(四)--流程控制ForLoop和WhileLoop
- AI enterprise multi cloud storage architecture practice | Shenzhen potential technology sharing
- 枚举与#define 宏的区别
- 0 basic learning C language - digital tube
- Build op-tee development environment based on qemuv8
- 中国固态氧化物燃料电池技术进展与发展前景报告(2022版)
- 云原生技术--- 容器知识点
- [sdx62] wcn685x will bdwlan Bin and bdwlan Txt mutual conversion operation method
猜你喜欢

(18) LCD1602 experiment

Seata聚合 AT、TCC、SAGA 、 XA事务模式打造一站式的分布式事务解决方案

AdaViT——自适应选择计算结构的动态网络

新手程序员该不该背代码?

Memorabilia of domestic database in June 2022 - ink Sky Wheel

HDR image reconstruction from a single exposure using deep CNN reading notes

重磅新闻 | Softing FG-200获得中国3C防爆认证 为客户现场测试提供安全保障

Self made j-flash burning tool -- QT calls jlinkarm DLL mode

Leetcode: interview question 17.24 Maximum cumulative sum of submatrix (to be studied)

3DMax指定面贴图
随机推荐
Mysql database basic operations DML
基於 QEMUv8 搭建 OP-TEE 開發環境
Mise en place d'un environnement de développement OP - tee basé sur qemuv8
【数字IC手撕代码】Verilog无毛刺时钟切换电路|题目|原理|设计|仿真
LeetCode 练习——剑指 Offer 26. 树的子结构
Notes de développement du matériel (10): flux de base du développement du matériel, fabrication d'un module USB à RS232 (9): création de la Bibliothèque d'emballage ch340g / max232 SOP - 16 et Associa
小程序系统更新提示,并强制小程序重启并使用新版本
Solve project cross domain problems
Lora sync word settings
Data storage (1)
OpenCV VideoCapture. Get() parameter details
MySQL教程的天花板,收藏好,慢慢看
Aardio - 不声明直接传float数值的方法
C# 三种方式实现Socket数据接收
pytorch_ Yolox pruning [with code]
Assembly and interface technology experiment 5-8259 interrupt experiment
【LeetCode】19、 删除链表的倒数第 N 个结点
CCNA-思科网络 EIGRP协议
What are the interface tests? What are the general test points?
2022-07-05 stonedb的子查询处理解析耗时分析