当前位置:网站首页>一些二进制位操作
一些二进制位操作
2022-07-27 14:05:00 【押切徹】
“>>” : 右移操作:
注意:Java中的“>>”是算数右移:舍弃最低位,高位用符号位填补;
“>>>”是逻辑右移:舍弃最低位,高位用 0 填补。
“|”:或操作,两边有一个是1就是1,可以相当于加法用,如二进制的(10|1)就是(11)
整数集合set位运算
整数集合做标志时,比如回溯时的visited标志数组
vstd 访问 i :vstd | (1 << i)
vstd 离开 i :vstd & ~(1 << i)
vstd 不包含 i : not vstd & (1 << i)
并集 :A | B
交集 :A & B
全集 :(1 << n) - 1
补集 :((1 << n) - 1) ^ A
子集 :(A & B) == B
判断是否是 2 的幂 :A & (A - 1) == 0
最低位的 1 变为 0 :n &= (n - 1)
最低位的 1:A & (-A),最低位的 1 一般记为 lowbit(A) (取到一个数的最低位的1和之后的0,其他位都变成0)(一个数的相反数是这个数按位取反之后加1)
异或运算的性质(^):
异或运算满足交换律和结合律;
任意整数和自身做异或运算的结果都等于 0,即x⊕x=0;
任意整数和 00 做异或运算的结果都等于其自身,即 x⊕0=0⊕x=x。
边栏推荐
- 这年头谁还不会抓包,WireShark 抓包及常用协议分析送给你!
- The database uses PSQL and JDBC to connect remotely and disconnect automatically from time to time
- CPU、GPU、NPU的区别
- 视觉系统设计实例(halcon-winform)-9.文字显示
- [work] about technical architecture
- 如何做好企业系统漏洞评估
- What is the execution method of the stand-alone parallel query of PostgreSQL?
- 移动端使用vantUI的list组件,多个tab项来回切换时,列表加载多次导致数据无法正常展示
- Lesson 3: SPFA seeking the shortest path
- LeetCode 1143. 最长公共子序列 动态规划/medium
猜你喜欢
Database storage series (1) column storage

视觉系统设计实例(halcon-winform)-10.PLC通讯

Understand JS execution context in an article

User question understanding and answer content organization for epidemic disease Science Popularization

Research on Chinese idiom metaphorical knowledge recognition and relevance based on transfer learning and text enhancement

Redis

于不确定中见“安全感” 沃尔沃2022年中问道

Passive income: return to the original and safe two ways to earn

Shell programming specifications and variables

LeetCode 面试题 17.21. 直方图的水量 双指针,单调栈/hard
随机推荐
通过VN1630/VN7640的I/O功能来确认电源设置电压的时间精确度
STM32F103C8T6在Arduino框架下驱动SH1106 1.3“ IIC OLED显示
Automatically configure SSH password free login and cancel SSH password free configuration script
How to deploy open source Siyuan privately
获取Unity打开摄像头第一帧有画面的数据
被动收入:回归原始且安全的两种赚取方法
An example of building 3D effects on the web based on three.js
How to help enterprises optimize office management
[Yunxiang book club issue 13] multimedia processing tool ffmpeg tool set
[cache series] completely solve the problems of cache avalanche, breakdown and penetration
网络设备硬核技术内幕 路由器篇 21 可重构的路由器
Visual system design example (Halcon WinForm) -9. text display
How to do well in enterprise system vulnerability assessment
What if win11 wallpaper turns black? The solution of win11 wallpaper blackening
LeetCode 81. 搜索旋转排序数组 II 二分/medium
LeetCode 341.扁平化嵌套列表迭代器 dfs,栈/ Medium
周鸿祎:数字安全能力落后也会挨打
idea打jar包与引入jar包
JS what is declaration in advance? The order of function and variable declaration in advance (the foreshadowing of execution context)
对话框管理器第三章:创建控件