当前位置:网站首页>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;
}
边栏推荐
- 0 basic learning C language - digital tube
- Clip +json parsing converts the sound in the video into text
- How do I write Flask's excellent debug log message to a file in production?
- [线性代数] 1.3 n阶行列式
- The nearest common ancestor of binary (search) tree ●●
- What are the interface tests? What are the general test points?
- Export MySQL table data in pure mode
- Management background --2 Classification list
- 中国VOCs催化剂行业研究与投资战略报告(2022版)
- HDR image reconstruction from a single exposure using deep CNN reading notes
猜你喜欢
新手程序员该不该背代码?
LeetCode 练习——剑指 Offer 26. 树的子结构
Management background --3, modify classification
0 basic learning C language - interrupt
RESNET rs: Google takes the lead in tuning RESNET, and its performance comprehensively surpasses efficientnet series | 2021 arXiv
硬件开发笔记(十): 硬件开发基本流程,制作一个USB转RS232的模块(九):创建CH340G/MAX232封装库sop-16并关联原理图元器件
UE4蓝图学习篇(四)--流程控制ForLoop和WhileLoop
LeetCode刷题(十一)——顺序刷题51至55
pytorch_YOLOX剪枝【附代码】
如何用程序确认当前系统的存储模式?
随机推荐
Classification, function and usage of MySQL constraints
Seata aggregates at, TCC, Saga and XA transaction modes to create a one-stop distributed transaction solution
PVL EDI 项目案例
(18) LCD1602 experiment
The nearest common ancestor of binary (search) tree ●●
Web APIs DOM 时间对象
手写ABA遇到的坑
2022-07-05 使用tpcc对stonedb进行子查询测试
中国1,4-环己烷二甲醇(CHDM)行业调研与投资决策报告(2022版)
硬件开发笔记(十): 硬件开发基本流程,制作一个USB转RS232的模块(九):创建CH340G/MAX232封装库sop-16并关联原理图元器件
基於 QEMUv8 搭建 OP-TEE 開發環境
NetXpert XG2帮您解决“布线安装与维护”难题
0 basic learning C language - interrupt
C# 三种方式实现Socket数据接收
基于 QEMUv8 搭建 OP-TEE 开发环境
3DMAX assign face map
Balanced Multimodal Learning via On-the-fly Gradient Modulation(CVPR2022 oral)
2022年6月国产数据库大事记-墨天轮
RESNET rs: Google takes the lead in tuning RESNET, and its performance comprehensively surpasses efficientnet series | 2021 arXiv
自制J-Flash烧录工具——Qt调用jlinkARM.dll方式