当前位置:网站首页>整数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
边栏推荐
- 9大最佳工程施工项目管理系统
- Common cross domain scenarios
- What has become a difficult problem for most people to change careers, so why do many people study software testing?
- 【程序员2公务员】关于体制调研的一些常见问题总结
- 华为无线设备配置WPA2-802.1X-AES安全策略
- Delete in elasticserach_ by_ What is the mechanism of query?
- 深度学习训练和测试时出现问题:error: the following arguments are required: --dataroot,解决:训练文件的配置方法和测试文件的配置方法
- Bingbing's learning notes: classes and objects (Part 1)
- [300 + selected interview questions from big companies continued to share] big data operation and maintenance sharp knife interview question column (V)
- Paddlepaddle 34 adjust the layer structure and forward process of the model (realize the addition, deletion, modification and forward modification of the layer)
猜你喜欢

【论文笔记】EFFICIENT CNN ARCHITECTURE DESIGN GUIDED BY VISUALIZATION

Have you got the advanced usage of pytest?

Million level element optimization: real-time vector tile service based on PG and PostGIS

J1 常用的DOS命令(P25)

Teach you to use cann to convert photos into cartoon style
![[unity entry plan] interface Introduction (1) -scene view](/img/88/dee292cb90cd740640018e7260107f.png)
[unity entry plan] interface Introduction (1) -scene view
![[cloud native] the ribbon is no longer used at the bottom of openfeign, which started in 2020.0.x](/img/7e/1d27e3f1856ab8c6cbfc5221c717bb.png)
[cloud native] the ribbon is no longer used at the bottom of openfeign, which started in 2020.0.x

集群聊天服务器:项目问题汇总
![[unity introduction plan] interface Introduction (2) -games view & hierarchy & Project & Inspector](/img/b0/ef084f4391795a1369b0f46a2de8d6.png)
[unity introduction plan] interface Introduction (2) -games view & hierarchy & Project & Inspector

Cluster chat server: summary of project problems
随机推荐
JS cannot get content disposition in headers
线代(矩阵‘)
How to use network installation to deploy multiple virtual servers in KVM environment
Learn when playing No 7 | don't study this holiday, study only
全新8.6版本SEO快排系统(可源码级搭建)
【Unity入门计划】制作我的第一个小游戏
[ES6] function parameters, symbol data types, iterators and generators
【程序员2公务员】关于体制调研的一些常见问题总结
[unity introduction program] basic concepts -2d rigid body 2D
Have you got the advanced usage of pytest?
【程序员2公务员】三、资源搜集
[unity entry program] make my first little game
[programmer 2 Civil Servant] summary of some common problems about system research
What are runtimecompiler and runtimeonly
Paddlepaddle 34 adjust the layer structure and forward process of the model (realize the addition, deletion, modification and forward modification of the layer)
[pytorch] the most common function of view
Practical skills -- some solutions to small problems
Install homebrew, NVM and verdaccio to build a private NPM warehouse
【Unity入门计划】基本概念-预制件 Prefab
深度学习训练和测试时出现问题:error: the following arguments are required: --dataroot,解决:训练文件的配置方法和测试文件的配置方法