当前位置:网站首页>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;
}
边栏推荐
- Hardware development notes (10): basic process of hardware development, making a USB to RS232 module (9): create ch340g/max232 package library sop-16 and associate principle primitive devices
- MySQL----初识MySQL
- Aardio - 利用customPlus库+plus构造一个多按钮组件
- 硬件开发笔记(十): 硬件开发基本流程,制作一个USB转RS232的模块(九):创建CH340G/MAX232封装库sop-16并关联原理图元器件
- 12、 Start process
- Seata聚合 AT、TCC、SAGA 、 XA事务模式打造一站式的分布式事务解决方案
- MySQL数据库基本操作-DML
- Inno Setup 打包及签名指南
- const关键字
- PVL EDI project case
猜你喜欢
AdaViT——自适应选择计算结构的动态网络
Leetcode: interview question 17.24 Maximum cumulative sum of submatrix (to be studied)
重磅新闻 | Softing FG-200获得中国3C防爆认证 为客户现场测试提供安全保障
Self made j-flash burning tool -- QT calls jlinkarm DLL mode
3DMAX assign face map
Netxpert xg2 helps you solve the problem of "Cabling installation and maintenance"
Hardware development notes (10): basic process of hardware development, making a USB to RS232 module (9): create ch340g/max232 package library sop-16 and associate principle primitive devices
[leetcode daily clock in] 1020 Number of enclaves
2021 geometry deep learning master Michael Bronstein long article analysis
Web APIs DOM 时间对象
随机推荐
Web APIs DOM time object
如何实现文字动画效果
volatile关键字
关于声子和热输运计算中BORN电荷和non-analytic修正的问题
树的先序中序后序遍历
Installation and use of labelimg
二分图判定
OpenCV VideoCapture. Get() parameter details
Applet system update prompt, and force the applet to restart and use the new version
HDR image reconstruction from a single exposure using deep CNN reading notes
Common sense: what is "preservation" in insurance?
CocosCreator+TypeScripts自己写一个对象池
如何用程序确认当前系统的存储模式?
AI enterprise multi cloud storage architecture practice | Shenzhen potential technology sharing
MySQL----初识MySQL
LeetCode 练习——剑指 Offer 26. 树的子结构
SQL Server生成自增序号
extern关键字
Netxpert xg2 helps you solve the problem of "Cabling installation and maintenance"
雅思口语的具体步骤和时间安排是什么样的?