当前位置:网站首页>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.
边栏推荐
- 程序员如何优雅地解决线上问题?
- R language ggplot2 visualization: use the ggdensity function of the ggpubr package to visualize density plots, use the stat_central_tendency function to add mean vertical lines to the density and cust
- MarkDown公式指导手册
- 一文带你读懂云原生、微服务与高可用
- 【倒计时5天】探索音画质量提升背后的秘密,千元大礼等你来拿
- PanGu-Coder:函数级的代码生成模型
- Windows 安装PostgreSQL
- 数字证书原理
- 一文带你彻底厘清 Isito 中的证书工作机制
- CAN通信标准帧和扩展帧介绍
猜你喜欢
win10系统重装,无法登录进行同步的情况下chrome数据恢复
SAP ABAP OData 服务如何支持创建(Create)操作试读版
观察者模式
数据湖 delta lake和spark版本对应关系
[Open class preview]: Research and application of super-resolution technology in the field of video quality enhancement
Audio and Video Technology Development Weekly | 256
JMP Pro 16.0软件安装包下载及安装教程
[5 days countdown] to explore the secret behind the great quality promotion, gift waiting for you to take of $one thousand
字体反爬之好租
【讲座分享】“营收“看金融
随机推荐
CAN通信的数据帧和远程帧
【倒计时5天】探索音画质量提升背后的秘密,千元大礼等你来拿
Audio and Video Technology Development Weekly | 256
Grafana9.0发布,Prometheus和Loki查询生成器、全新导航、热图面板等新功能!
为什么最大值加一等于最小值
Visualization of lag correlation of two time series data in R language: use the ccf function of the forecast package to draw the cross-correlation function, and analyze the lag correlation according t
Complete Raiders of JS Data Type Conversion
PanGu-Coder:函数级的代码生成模型
数字孪生北京故宫,元宇宙推进旅游业进程
kubernetes之DaemonSet以及滚动更新
AI目标分割能力,无需绿幕即可实现快速视频抠图
[Open class preview]: Research and application of super-resolution technology in the field of video image quality enhancement
The four methods of judging JS data type
[Unity3D Plugin] AVPro Video Plugin Share "Video Player Plugin"
深入解析volatile关键字
力扣160题,相交链表
多线程案例——定时器
字体反爬之好租
观察者模式
动态库、静态库浅析