当前位置:网站首页>Bit operation rules
Bit operation rules
2022-07-06 05:52:00 【Python's path to immortality】
An operator
An operator | effect | priority |
---|---|---|
~ | According to the not | 1 |
<< and >> | Move left Move right | 2 |
& | Bitwise AND | 3 |
^ | Bitwise XOR | 4 |
or | Press bit or | 5 |
Please refer to the link for details of hexadecimal conversion :https://blog.csdn.net/qq_48434912/article/details/122898217?spm=1001.2014.3001.5502
1、 According to the not (~)
Monocular operator , In binary ,1 change 0,0 change 1.
2、 Bitwise AND (&)、 Press bit or (|)
Binocular operator , In binary .
1&1=1 1|1=1
0&0=0 0|0=0
1&0=0 1|0=1
0&1=0 0|1=1
3、 Exclusive or (^)
Binocular operator , In binary .
Operational rules : The same XOR of two numbers is 0, Different XOR is 1.
1^1=0
0^0=0
1^0=1
0^1=1
characteristic :
- And 1 XOR has Overturnability (0 change 1,1 change 0)
- And 0 XOR has Keep sex ( XOR is itself )
- XOR with a binary number for two consecutive times and then restore the original value unchanged , have Restorative
- XOR operation has Exchangeability (a ^ b = b ^ a)
4、 Shift Operators ( Shift left <<)
Binocular operator , In binary .
The rules : High position regardless 0 or 1 All discarded , The low vacancy is in 0 fill .
features : There is nothing discarded in the high position 1 when , Move left i position , become 2^i times .
20<<2
20 Binary system :0001 0100
Move two places to the left :0101 0000
result :20*2^2=80
5、 Shift Operators ( Shift right >>)
The rules : Low regardless 0 or 1 All discarded , The high empty bit fills the sign bit for the signed number ( Fill in with a positive number 0, Negative number filling 1), For unsigned numbers, fill 0.
features : There is nothing discarded in the low order 1 when , Move right i position , become 2^-i times , That is, it shrinks 2^i times .
20>>2
20 Binary system :0001 0100
Move two places to the right :0000 0101
result :20*2^-2=5
notes : If there is no assignment operation after bit operation , Then the value of the variable remains unchanged .
边栏推荐
- Text classification still stays at Bert? The dual contrast learning framework is too strong
- Application Security Series 37: log injection
- [Jiudu OJ 07] folding basket
- 华为路由器如何配置静态路由
- [SQL Server Express Way] - authentification et création et gestion de comptes utilisateurs
- C language learning notes (mind map)
- AUTOSAR从入门到精通番外篇(十)-嵌入式S19文件解析
- Pytorch代码注意的细节,容易敲错的地方
- 清除浮动的方式
- Migrate Infones to stm32
猜你喜欢
养了只小猫咪
Station B, Master Liu Er - dataset and data loading
Analysis report on development trends and investment planning of China's methanol industry from 2022 to 2028
- [email protected]树莓派"/>
[email protected]树莓派
[paper reading] nflowjs: synthetic negative data intensive anomaly detection based on robust learning
Winter 2021 pat class B problem solution (C language)
CoDeSys note 2: set coil and reset coil
Leetcode 701 insertion operation in binary search tree -- recursive method and iterative method
Sequoiadb Lake warehouse integrated distributed database, June 2022 issue
The difference and usage between continue and break
随机推荐
ArcGIS应用基础4 专题图的制作
入侵检测领域数据集总结
Web service connector: Servlet
wib3.0 跨越,在跨越(ง •̀_•́)ง
LeetCode_ String inversion_ Simple_ 557. Reverse word III in string
Database: ODBC remote access SQL Server2008 in oracel
H3C V7版本交换机配置IRF
Classes and objects (I) detailed explanation of this pointer
Demander le Code de texte standard correspondant à un centre de travail dans l'ordre de production
B站刘二大人-反向传播
Wib3.0 leapfrogging, in leapfrogging (ง • ̀_•́) ง
(column 22) typical column questions of C language: delete the specified letters in the string.
B站刘二大人-线性回归 Pytorch
Raised a kitten
Station B, Mr. Liu Er - multiple logistic regression, structure 7
Cannot build artifact 'test Web: War expanded' because it is included into a circular depend solution
Analysis of grammar elements in turtle Library
OSPF configuration command of Huawei equipment
网站进行服务器迁移前应做好哪些准备?
Anti shake and throttling are easy to understand