当前位置:网站首页>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.
边栏推荐
猜你喜欢
随机推荐
uniapp读取和写入文件
【公开课预告】:超分辨率技术在视频画质增强领域的研究与应用
How to Integrate Your Service Registry with Istio?
Programmer's self-cultivation
安全又省钱,“15岁”老小区用上管道燃气
Find objects with the same property value Cumulative number Summarize
bpmn-process-designer基础上进行自定义样式(工具、元素、菜单)
大中型网站列表页翻页过多怎么优化?
formatdatetime函数 mysql(date sub函数)
并发编程10大坑,你踩过几个?
SQL function SQRT
高仿项目协作工具【Worktile】,从零带你一步步实现组织架构、网盘、消息、项目、审批等功能
初级必备:单例模式的7个问题
浏览器存储
一文带你读懂云原生、微服务与高可用
SQL函数 %SQLSTRING
腾讯云原生:Areaki Mesh 在 2022 冬奥会视频直播应用中的服务网格实践
[Open class preview]: Research and application of super-resolution technology in the field of video quality enhancement
阿里云官方 Redis 开发规范
SQL函数 SQUARE








