当前位置:网站首页>整数a按位取反(~)后的值为-(a+1)
整数a按位取反(~)后的值为-(a+1)
2022-07-25 07:36:00 【hnjzsyjyj】
【理解按位取反(~)前需要知晓的原码、反码、补码规则】
数据在内存中是以有符号数二进制的补码形式存储的。有符号整数的二进制表示中,最高位为符号位(正整数为0,负整数为1),这也是有符号整数名称的由来。
● 正数的原码、反码、补码都相同。
● 负数的反码等于原码符号位不变,其余各位取反;负数的补码等于反码加1。
【按位取反的运算实例如下】
负数:-1
原码:1000 0001
反码:1111 1110 (符号位不变)
补码:1111 1111 (符号位不变)
按位取反:0000 0000 (符号位也取反)
由于符号位为0,为正数。故补码等于按位取反后的值 0000 0000,其十进制为0。也即-(-1+1)=0
-------------------------------------
负数:-10
原码:1000 1010
反码:1111 0101 (符号位不变)
补码:1111 0110 (符号位不变)
按位取反:0000 1001 (符号位也取反)
由于符号位为0,为正数。故补码等于按位取反后的值 1111 0110,其十进制为9。也即-(-10+1)=9
=============================================================================
正数:1
原码:0000 0001
反码:0000 0001 (符号位不变)
补码:0000 0001 (符号位不变)
按位取反:1111 1110 (符号位也取反)
由于符号位为1,为负数。故有:
原码:1111 1110
反码:1000 0001 (符号位不变)
补码:1000 0010 (符号位不变)
故补码对应的十进制为-2。也即-(1+1)=-2
-------------------------------------
正数:10
原码:0000 1010
反码:0000 1010 (符号位不变)
补码:0000 1010 (符号位不变)
按位取反:1111 0101 (符号位也取反)
由于符号位为1,为负数。故有:
原码:1111 0101
反码:1000 1010 (符号位不变)
补码:1000 1011 (符号位不变)
故补码对应的十进制为-11。也即-(10+1)=-110既不是正数,也不是负数。但对其按位取反的运算规则同上。
整数:0
原码:0000 0000
反码:0000 0000 (符号位不变)
补码:0000 0000 (符号位不变)
按位取反:1111 1111 (符号位也取反)
由于符号位为1,为负数。故有:
原码:1111 1111
反码:1000 0000 (符号位不变)
补码:1000 0001 (符号位不变)
故补码对应的十进制为-1。也即-(0+1)=-1综上:
整数a按位取反(~)后的值为-(a+1)
【参考文献】
https://blog.csdn.net/hnjzsyjyj/article/details/125857019
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
边栏推荐
- Servlet常用类剖析
- Robot Framework移动端自动化测试----01环境安装
- 全新8.6版本SEO快排系统(可源码级搭建)
- Learn no when playing 9 | enterprise knowledge management is so simple because it uses
- NLP hotspots from ACL 2022 onsite experience
- Configuring WAPI certificate security policy for Huawei wireless devices
- Problems in deep learning training and testing: error: the following arguments are required: --dataroot, solution: the configuration method of training files and test files
- Lidar construction map (overlay grid construction map)
- 华为无线设备STA黑白名单配置命令
- Simulation Implementation of list
猜你喜欢

diagramscene工程难点分析

What has become a difficult problem for most people to change careers, so why do many people study software testing?

【微信小程序】全局样式、局部样式、全局配置

转行学什么成为了一大部分人的难题,那么为什么很多人学习软件测试呢?

QT6 with vs Code: compiling source code and basic configuration

Pads export Gerber file

QT learning diary 20 - aircraft war project

Introduction to Manhattan distance
![[unity introduction program] basic concepts -2d rigid body 2D](/img/67/537e9935bb0f2539945032cadcf232.png)
[unity introduction program] basic concepts -2d rigid body 2D

NLP hotspots from ACL 2022 onsite experience
随机推荐
How to do a good job in safety development?
【刷题笔记】搜索插入位置(二分法的活用)
MATLAB自编程系列(1)---角分布函数
[unity entry program] basic concept trigger
RPC通信原理与项目技术选型
[pytorch] the most common function of view
Million level element optimization: real-time vector tile service based on PG and PostGIS
Paper reading: UNET 3+: a full-scale connected UNET for medical image segmentation
[notes] search rotation sort array
冰冰学习笔记:类与对象(上)
UXDB怎么从日期值中提取时分秒?
Offline base tile, which can be used for cesium loading
Load capacity - sorting out the mind map that affects load capacity
Flinkcdc2.0 uses flinksql to collect MySQL
Leetcode118. Yanghui triangle
New version 8.6 SEO quick release system (can be built at source level)
Summary of differences between data submission type request payload and form data
Tunnel broadcasting and wireless trunking communication broadcasting system - the case of Tiantaishan tunnel
DJI内推码(一码一用,限时内推)
[paper notes] next vit: next generation vision transformer for efficient deployment in real industry