当前位置:网站首页>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 .
边栏推荐
- Practice sharing: how to safely and quickly migrate from CentOS to openeuler
- [Jiudu OJ 08] simple search x
- [C language syntax] the difference between typedef struct and struct
- Node 之 nvm 下载、安装、使用,以及node 、nrm 的相关使用
- Memory and stack related concepts
- Closure, decorator
- 29io stream, byte output stream continue write line feed
- Game push: image / table /cv/nlp, multi-threaded start!
- 数字经济破浪而来 ,LTD是权益独立的Web3.0网站?
- 类和对象(一)this指针详解
猜你喜欢
Market development prospect and investment risk assessment report of China's humidity sensor industry from 2022 to 2028
Jushan database appears again in the gold fair to jointly build a new era of digital economy
网络协议模型
B站刘二大人-数据集及数据加载 Lecture 8
Raised a kitten
什么是独立IP,独立IP主机怎么样?
Game push image / table /cv/nlp, multi-threaded start
嵌入式面试题(四、常见算法)
Station B Liu Erden softmx classifier and MNIST implementation -structure 9
[happy Spring Festival] if you feel happy, dance
随机推荐
C language learning notes (mind map)
Summary of data sets in intrusion detection field
网站进行服务器迁移前应做好哪些准备?
[force buckle]43 String multiplication
Redis6 cluster setup
Li Chuang EDA learning notes 12: common PCB board layout constraint principles
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Luogu [Beginner Level 4] array p1427 number game of small fish
(column 22) typical column questions of C language: delete the specified letters in the string.
Quantitative description of ANC noise reduction
How to use PHP string query function
B站刘二大人-反向传播
如何在业务代码中使用 ThinkPHP5.1 封装的容器内反射方法
【SQL server速成之路】——身份驗證及建立和管理用戶賬戶
28io stream, byte output stream writes multiple bytes
Redis消息队列
SequoiaDB湖仓一体分布式数据库2022.6月刊
Winter 2021 pat class B problem solution (C language)
华为路由器如何配置静态路由
Database: ODBC remote access SQL Server2008 in oracel