当前位置:网站首页>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;
}

边栏推荐
- Should novice programmers memorize code?
- 硬件开发笔记(十): 硬件开发基本流程,制作一个USB转RS232的模块(九):创建CH340G/MAX232封装库sop-16并关联原理图元器件
- 基于 QEMUv8 搭建 OP-TEE 开发环境
- Web APIs DOM time object
- 2022-07-04 the high-performance database engine stonedb of MySQL is compiled and run in centos7.9
- 2022-07-05 使用tpcc对stonedb进行子查询测试
- Chapter 4: talk about class loader again
- Inno Setup 打包及签名指南
- Memorabilia of domestic database in June 2022 - ink Sky Wheel
- CCNA Cisco network EIGRP protocol
猜你喜欢

HDR image reconstruction from a single exposure using deep CNNs阅读札记

2022年6月国产数据库大事记-墨天轮

LeetCode刷题(十一)——顺序刷题51至55

Export MySQL table data in pure mode

CCNA-思科网络 EIGRP协议

在IPv6中 链路本地地址的优势

(十八)LCD1602实验

pytorch_YOLOX剪枝【附代码】

如何用程序确认当前系统的存储模式?

Heavyweight news | softing fg-200 has obtained China 3C explosion-proof certification to provide safety assurance for customers' on-site testing
随机推荐
What are the interface tests? What are the general test points?
空结构体多大?
signed、unsigned关键字
Attack and defense world miscall
NPDP认证|产品经理如何跨职能/跨团队沟通?
Inno setup packaging and signing Guide
HDR image reconstruction from a single exposure using deep CNN reading notes
CCNA Cisco network EIGRP protocol
void关键字
Export MySQL table data in pure mode
Aardio - 利用customPlus库+plus构造一个多按钮组件
Improving Multimodal Accuracy Through Modality Pre-training and Attention
【数字IC手撕代码】Verilog无毛刺时钟切换电路|题目|原理|设计|仿真
LeetCode 练习——剑指 Offer 26. 树的子结构
【无标题】
leetcode:面试题 17.24. 子矩阵最大累加和(待研究)
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
[Digital IC hand tearing code] Verilog burr free clock switching circuit | topic | principle | design | simulation
MySQL数据库基本操作-DML
Assembly and interface technology experiment 5-8259 interrupt experiment