当前位置:网站首页>一些二进制位操作
一些二进制位操作
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。
边栏推荐
- Stm32f103c8t6 drives sh1106 1.3 "IIC OLED display under Arduino frame
- 微信小程序实现音乐搜索页面
- [ManageEngine] what is Siem
- telnet远程登录aaa模式详解【华为eNSP】
- STM32F103C8T6在Arduino框架下驱动ssd1306 0.96“ IIC OLED显示
- If we were the developer responsible for repairing the collapse of station B that night
- 正向代理与反向代理
- Docker practical experience: deploy mysql8 master-slave replication on docker
- Disk troubleshooting of kubernetes node
- 网络设备硬核技术内幕 路由器篇 4 贾宝玉梦游太虚幻境(下)
猜你喜欢

电子制造行业的数字化转型突破点在哪?精益制造是关键

这年头谁还不会抓包,WireShark 抓包及常用协议分析送给你!

See "sense of security" in uncertainty Volvo asked in 2022

移动端使用vantUI的list组件,多个tab项来回切换时,列表加载多次导致数据无法正常展示

What if win11 wallpaper turns black? The solution of win11 wallpaper blackening

Visual system design example (Halcon WinForm) -9. text display

Kubernetes CNI 分类/运行机制

CPU、GPU、NPU的区别

被动收入:回归原始且安全的两种赚取方法

Visual system design example (Halcon WinForm) -10. PLC communication
随机推荐
Timestamp of AAC, h264, etc
DVWA full level customs clearance tutorial
同花顺开户在手机开户安全吗?
[ManageEngine] what is Siem
Get the data of the first frame of unity's open camera
Is it safe for Guosen Securities to open a mobile account? Is Zhongshan securities reliable
STM32 - capacitive touch button experiment
Graphical SQL is too vivid
FPGA timing constraint sharing 04_ Output delay constraint
C language layered understanding (C language array)
Import the virtual machine officially made by Kali Linux into Oracle VirtualBox
Why is there no unified quotation for third-party testing fees of software products?
软件产品第三方测试费用为什么没有统一的报价?
数据库使用psql及jdbc进行远程连接,不定时自动断开的解决办法
See "sense of security" in uncertainty Volvo asked in 2022
获取Unity打开摄像头第一帧有画面的数据
Forward proxy and reverse proxy
Understand the evolution of redis architecture in one article
DirectX 入门知识
NEFU118 n! How many zeros are there after [basic theorem of arithmetic]