当前位置:网站首页>Why does the maximum plus one equal the minimum
Why does the maximum plus one equal the minimum
2022-08-01 13:02:00 【51CTO】
Sometimes the maximum value is accidentally added in the program1,We will get a negative number,This negative number is the minimum value for this data type.
下面看一个示例:
运行结果:
从结果可以看出:The largest integer plus one does indeed become the smallest integer,This is more evident from their binary form.When calculating inside the computer, the addition operation is performed in two's complement form.很显然,最大的数01111111111111111111111111111111+1=10000000000000000000000000000000,这里的10000000000000000000000000000000是-2147483648的补码形式.
If we convert the data type into a data type with a larger storage capacity during the operation,There will be no such result that this becomes a negative number.2147483647L + 1是long型的2147483647+1This will not overflow into a negative number.
此外,还需要注意的是在Java和C#中int是32位,long是64位,We have no problem converting this way.但是在C++语言中short、int和longThe number of bits depends on the operating system.我们只能说short<=int<=long,Of course, the two equal signs do not hold at the same time.So sometimes we seelong long这样的写法,long long是比longtype with larger capacity.在VC++中long long也写作_int64.
边栏推荐
- 芝加哥丰田技术学院 | Leveraging Natural Supervision for Language Representation Learning and Generation(利用自然监督进行语言表示学习和生成)
- leetcode:1201. 丑数 III【二分 + 数学 + 容斥原理】
- 如何将第三方服务中心注册集成到 Istio ?
- 数字证书原理
- Audio and Video Technology Development Weekly | 256
- Pytest e-commerce project combat (below)
- Grafana 9.0 released, Prometheus and Loki query builders, new navigation, heatmap panels and more!
- 找出相同属性值的对象 累加数量 汇总
- CAN通信的数据帧和远程帧
- SQL函数 %SQLSTRING
猜你喜欢
随机推荐
[Community Star Selection] Issue 24 August Update Plan | Keep writing, refuse to lie down!More original incentive packages, as well as Huawei WATCH FIT watches!
The four methods of judging JS data type
CAN通信的数据帧和远程帧
[Nodejs] fs module of node
The CAN communication standard frame and extended frame is introduced
How do programmers solve online problems gracefully?
(ES6 and above and TS) Map object to array
Complete Raiders of JS Data Type Conversion
PanGu-Coder:函数级的代码生成模型
MarkDown公式指导手册
CloudCompare & PCL ICP registration (point to face)
阿里云官方 Redis 开发规范
MySQL调优
Process sibling data into tree data
Simulation implementation of new of Js handwritten function
Detailed explanation of table join
Js手写函数之new的模拟实现
【讲座分享】“营收“看金融
Istio Meetup China: Full Stack Service Mesh - Aeraki Helps You Manage Any Layer 7 Traffic in an Istio Service Mesh
华盛顿大学、Allen AI 等联合 | RealTime QA: What's the Answer Right Now?(实时 QA:现在的答案是什么?)









