当前位置:网站首页>While (~scanf ("%d", & n)) is equivalent to while (scanf ("%d", & n)! =eof)
While (~scanf ("%d", & n)) is equivalent to while (scanf ("%d", & n)! =eof)
2022-07-25 07:40:00 【hnjzsyjyj】
【 Knowledge point 】
while(~scanf("%d", &n)) Equivalent to while(scanf("%d",&n)!=EOF)
among ,~ yes According to the not .
If scanf("%d", &n) Function successfully entered , Then return the number of input integers 1.1 Bitwise negation results in -2. by True.
If scanf("%d", &n) Function has no input or input error , Then return to -1.-1 Bitwise negation results in 0. by False.
Understanding bitwise negation (~) The original code you need to know before 、 Inverse code 、 The complement rule :
Data is stored in memory in the form of the complement of signed binary numbers . In the binary representation of signed integers , The highest bit is Sign bit ( The positive integer is 0, Negative integer is 1), This is also the origin of signed integer names .
The original code of a positive number 、 Inverse code 、 The complement is the same .
The inverse of a negative number is equal to the sign bit of the original code , The rest of you take the opposite ; The complement of a negative number is the inverse plus 1.
Examples of bitwise negation operations are as follows :
negative :-1
Original code :1000 0001
Inverse code :1111 1110 ( The sign bits remain the same )
Complement code :1111 1111 ( The sign bits remain the same )
According to the not :0000 0000 ( The sign bit is also reversed )
Because the sign bit is 0, Is a positive number . Therefore, complement is equal to the value after bitwise inversion 0000 0000, Its decimal system is 0. That is to say -(-1+1)=0
-------------------------------------
negative :-10
Original code :1000 1010
Inverse code :1111 0101 ( The sign bits remain the same )
Complement code :1111 0110 ( The sign bits remain the same )
According to the not :0000 1001 ( The sign bit is also reversed )
Because the sign bit is 0, Is a positive number . Therefore, complement is equal to the value after bitwise inversion 1111 0110, Its decimal system is 9. That is to say -(-10+1)=9
=============================================================================
Positive numbers :1
Original code :0000 0001
Inverse code :0000 0001 ( The sign bits remain the same )
Complement code :0000 0001 ( The sign bits remain the same )
According to the not :1111 1110 ( The sign bit is also reversed )
Because the sign bit is 1, It's a negative number . There are :
Original code :1111 1110
Inverse code :1000 0001 ( The sign bits remain the same )
Complement code :1000 0010 ( The sign bits remain the same )
Therefore, the decimal system corresponding to the complement is -2. That is to say -(1+1)=-2
-------------------------------------
Positive numbers :10
Original code :0000 1010
Inverse code :0000 1010 ( The sign bits remain the same )
Complement code :0000 1010 ( The sign bits remain the same )
According to the not :1111 0101 ( The sign bit is also reversed )
Because the sign bit is 1, It's a negative number . There are :
Original code :1111 0101
Inverse code :1000 1010 ( The sign bits remain the same )
Complement code :1000 1011 ( The sign bits remain the same )
Therefore, the decimal system corresponding to the complement is -11. That is to say -(10+1)=-110 Not a positive number , It's not a negative number . But the operation rule of bitwise negation is the same as above .
Integers :0
Original code :0000 0000
Inverse code :0000 0000 ( The sign bits remain the same )
Complement code :0000 0000 ( The sign bits remain the same )
According to the not :1111 1111 ( The sign bit is also reversed )
Because the sign bit is 1, It's a negative number . There are :
Original code :1111 1111
Inverse code :1000 0000 ( The sign bits remain the same )
Complement code :1000 0001 ( The sign bits remain the same )
Therefore, the decimal system corresponding to the complement is -1. That is to say -(0+1)=-1 Sum up :
Integers a According to the not (~) The value after is -(a+1)
【 reference 】
https://blog.csdn.net/hnjzsyjyj/article/details/119720322
https://blog.csdn.net/hnjzsyjyj/article/details/120794381
https://blog.csdn.net/qq_34681580/article/details/115248595
边栏推荐
- Summer Challenge harmonyos - slider slider for custom components
- 2-6. Automatic acquisition
- GBase 8a中关于--skip-networking 问题
- When providing digital talent services, Xi Zhi quickly opened its own digital school for each organization
- Common cross domain scenarios
- UXDB怎么从日期值中提取时分秒?
- QT learning diary 20 - aircraft war project
- 【微信小程序】全局样式、局部样式、全局配置
- [notes for question brushing] search the insertion position (flexible use of dichotomy)
- Problems during nanodet training: modulenotfounderror: no module named 'nanodet' solution
猜你喜欢

Introduction to Manhattan distance

SAP queries open Po (open purchase order)
![[paper notes] progressive layered extraction (PLE): a novel multi task learning (MTL) model for personalized](/img/a8/c5d14ec5f4a22f7925c6d7454b5a58.png)
[paper notes] progressive layered extraction (PLE): a novel multi task learning (MTL) model for personalized

【论文笔记】EFFICIENT CNN ARCHITECTURE DESIGN GUIDED BY VISUALIZATION

Analysis of difficulties in diagramscene project
![[paper notes] next vit: next generation vision transformer for efficient deployment in real industry](/img/ea/56881999a90f9c65f5f8768f9574bd.png)
[paper notes] next vit: next generation vision transformer for efficient deployment in real industry

Simulation Implementation of list

交叉熵计算公式

Today in history: Intel was founded; The first photo was posted on the world wide web; EBay spins off PayPal

What has become a difficult problem for most people to change careers, so why do many people study software testing?
随机推荐
【Unity入门计划】基本概念-2D碰撞体Collider 2D
Google Earth engine - Landsat 1985-2020 ecological remote sensing index resi calculation
Native form submission data
[programmer 2 Civil Servant] IV. common problems
How to use kotlin flow in Android projects
【Unity入门计划】界面介绍(1)-Scene视图
About --skip networking in gbase 8A
[paper notes] progressive layered extraction (PLE): a novel multi task learning (MTL) model for personalized
Oracle19采用自动内存管理,AWR报告显示SGA、PGA设置的过小了?
使用CycleGAN训练自己制作的数据集,通俗教程,快速上手
Leetcode (Sword finger offer) - 04. search in two-dimensional array
[unity introduction program] basic concepts -2d rigid body 2D
Analysis of difficulties in diagramscene project
深度学习制作数据集时,从长视频中指定每隔多少帧提取一张图像到指定文件路径的方法
DJI内推码(一码一用,限时内推)
深度学习训练和测试时出现问题:error: the following arguments are required: --dataroot,解决:训练文件的配置方法和测试文件的配置方法
3. Promise
[paper notes] next vit: next generation vision transformer for efficient deployment in real industry
Open source, innovators win, 2022 "science and innovation China" open source innovation list selection is fully open!
Simulation Implementation of list