当前位置:网站首页>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 .
边栏推荐
猜你喜欢
ArcGIS应用基础4 专题图的制作
[Jiudu OJ 07] folding basket
A master in the field of software architecture -- Reading Notes of the beauty of Architecture
How can large websites choose better virtual machine service providers?
SequoiaDB湖仓一体分布式数据库2022.6月刊
【SQL server速成之路】——身份驗證及建立和管理用戶賬戶
B站刘二大人-线性回归 Pytorch
实践分享:如何安全快速地从 Centos迁移到openEuler
- [email protected]树莓派"/>
[email protected]树莓派
Clear floating mode
随机推荐
Demander le Code de texte standard correspondant à un centre de travail dans l'ordre de production
Luogu [Beginner Level 4] array p1427 number game of small fish
wib3.0 跨越,在跨越(ง •̀_•́)ง
Redis message queue
[machine learning notes] univariate linear regression principle, formula and code implementation
Construction of yolox based on paste framework
Pay attention to the details of pytoch code, and it is easy to make mistakes
清除浮动的方式
[email protected]树莓派
Database: ODBC remote access SQL Server2008 in oracel
类和对象(一)this指针详解
Redis消息队列
The digital economy has broken through the waves. Is Ltd a Web3.0 website with independent rights and interests?
High quality coding tool clion
29io stream, byte output stream continue write line feed
[force buckle]43 String multiplication
養了只小猫咪
查询生产订单中某个(些)工作中心对应的标准文本码
Memory and stack related concepts
RustDesk 搭建一个自己的远程桌面中继服务器