当前位置:网站首页>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 .
边栏推荐
- Raised a kitten
- MIT6.s081-2020 Lab2 System Calls
- Market development prospect and investment risk assessment report of China's humidity sensor industry from 2022 to 2028
- 巨杉数据库再次亮相金交会,共建数字经济新时代
- Redis消息队列
- Rustdesk builds its own remote desktop relay server
- [Tang Laoshi] C -- encapsulation: classes and objects
- Clear floating mode
- Remember an error in MySQL: the user specified as a definer ('mysql.infoschema '@' localhost ') does not exist
- The usage and difference between strlen and sizeof
猜你喜欢

授予渔,从0开始搭建一个自己想要的网页

B站刘二大人-数据集及数据加载 Lecture 8

What is independent IP and how about independent IP host?

大型网站如何选择比较好的云主机服务商?

ArcGIS application foundation 4 thematic map making

RustDesk 搭建一个自己的远程桌面中继服务器

Node 之 nvm 下载、安装、使用,以及node 、nrm 的相关使用

巨杉数据库再次亮相金交会,共建数字经济新时代
![[Baiwen smart home] first day of the course_ Learn Embedded and understand the development mode of bare metal and RTOS](/img/ed/8d112054f31bd7e593050d1278b9f1.jpg)
[Baiwen smart home] first day of the course_ Learn Embedded and understand the development mode of bare metal and RTOS

B站刘二大人-反向传播
随机推荐
[machine learning notes] univariate linear regression principle, formula and code implementation
Station B Liu Erden linear regression pytoch
【经验】win11上安装visio
Yunxiaoduo software internal test distribution test platform description document
Auto.js学习笔记17:基础监听事件和UI简单的点击事件操作
授予渔,从0开始搭建一个自己想要的网页
OSPF configuration command of Huawei equipment
What is independent IP and how about independent IP host?
What preparations should be made for website server migration?
Embedded interview questions (I: process and thread)
P2802 回家
Selective parameters in MATLAB functions
YYGH-11-定时统计
C language learning notes (mind map)
类和对象(一)this指针详解
Practice sharing: how to safely and quickly migrate from CentOS to openeuler
Anti shake and throttling are easy to understand
[experience] when ultralso makes a startup disk, there is an error: the disk / image capacity is too small
如何在业务代码中使用 ThinkPHP5.1 封装的容器内反射方法
Redis message queue