当前位置:网站首页>C language integer value range - the problem of more than one negative number
C language integer value range - the problem of more than one negative number
2022-06-22 03:35:00 【A rainy spring night】
(Owed by: Happy rain in spring night http://blog.csdn.net/chunyexiyu)
Integer range , A negative number is one more , I wonder if everyone is curious ?
Take the single byte as the discussion point , Discuss it. :
BYTE/char The value range of type is :[-128, +127], Why -128, Why not -127?
Around this problem :
We know BYTE/char Type is 8 Bit , The highest bit is the sign bit , Then the rest 7 Yes. ;
7 What can bits express , from 0b0000000 To 0b1111111, Can express 0-127 The scope of the ;
Symbol bit 0 when , Express positive numbers ,0-127 The scope of just expresses ;
Symbol bit 1 when , Express negative numbers ,0-127 The scope of the , To express -0 To -127 Do you ?0 This number has been corrected 0 Expressed , that -0 What shall I do? ? Also to express 0 Do you ?
With this problem , We need to solve this problem ,-0 To -127 The scope of the , The actual number of values is 128 Species value , If all maps to negative numbers , Indeed, it is mapped to -1 To -128 The scope of ; As consumed in bits C Language , I won't waste this 1/256 Of value taking opportunities .
Select the mapping algorithm , Even if it comes to the complement head , Physical minimum 0b10000000 That is to say -0 To express -128, Physical maximum 0b11111111 To express the minimum -1, The mapping process produces .
alike short Range /int Range /int64 This is the case with scope , This will solve the problem +0/-0 Awkward expression .
At the same time, it has created c/c++/java/c# These languages , Range of shaping variables , The negative range is greater than a value in the positive range . Because of the complement mapping , Thus, the physical -0 Is mapped to the limit value on the range of negative numbers .
(Owed by: Happy rain in spring night http://blog.csdn.net/chunyexiyu)
边栏推荐
- 达梦数据库客户端屏蔽sql关键字
- 3de 新建仿真状态
- Nebula Graph学习篇2_版本v2.6.1之前的bug导致OOM
- Nepal graph learning Chapter 2_ A bug before version v2.6.1 caused OOM
- Splunk: Auto load Balanced TCP Output issue
- A component required a bean of type 'com.example.demo3.service.UserServiceImp' that could not be fou
- Rabbmitmq publish subscribe mode < 2 >
- rabbmitMQ 发布关键字模式<三>
- Implementation of synchronization and atomic operation by mutex mutex in golang concurrent programming
- std::move与std::forward右值引用研究
猜你喜欢

eu5,eu7,ex3,ex5安装第三方app

泛微 E-cology V9 信息泄露漏洞

Rabbmitmq simple mode < 1 >

CMD view the console output of hearts, diamonds, spades and clubs to solve the garbled code
![[nvme2.0b 12] NVM capacity model](/img/e5/c898cb1eeeabce757a2b07b08f9219.png)
[nvme2.0b 12] NVM capacity model

3de 移动物体的位置

Pan micro e-cology V9 information disclosure vulnerability
![[nvme2.0b 6] nvme queue model](/img/e9/d29001cebeebe9677b02ffb7c25726.png)
[nvme2.0b 6] nvme queue model

告警日志中出现ORA-48132 ORA-48170

2019年全国职业院校技能大赛中职组“网络空间安全”正式赛卷及其“答案”
随机推荐
powerdesigner CDM中联系理解
平衡二叉树——调整变换规则
AtCoder Beginner Contest 252(dijkstra,逆向思维)
mysql-索引创建、优化分析、索引优化
eu5,eu7,ex3,ex5安装第三方app
Rabbmitmq publishing keyword mode < 3 >
EU5, eu7, EX3, Ex5 install third-party apps
R data analysis: significance and practice of calibration curve and DCA curve in clinical prediction model
3de 新建仿真状态
2019年全国职业院校技能大赛中职组“网络空间安全”正式赛卷及其“答案”
1690. stone game vii- dynamic programming method
倍福 PLC 字符串类型string操作
How to do activities in beauty salons
golang标准库time
TX2 mirror source settings
Introduction and use of kubernetes
snappy格式解析
The cloned VMware virtual host network card cannot be started solution
AtCoder Regular Contest 142
微信小程序聊天 表情