当前位置:网站首页>位运算的一些操作
位运算的一些操作
2022-07-28 14:28:00 【飞天_】
按位与&操作通常用作将一个数的某些位清零或保留某些位操作
例如:把a的高8位清零
a & 0000000011111111
也就是将a & 255操作之后,就会实现将数字a的高8位位清零了
异或^操作的用途:
将某些特定的位翻转
例如对数0x10100001的第2和第3位翻转操作,那么
可以0x10100001 ^ 0x00000110
通过按位异或操作可以实现两个数的交换
例如交换A和B
A=0x10100001 B=0x00000110
A=A^B A=10100111
B=A^B B=10100001
A=A^B A=00000110
位运算的一些操作:
1、 乘除2
数字A左移n位表示 A*2^n
数字A右移n位表示A/2^n
2、 判断奇偶性
因为如果一个数位奇数,那么最后一位肯定为1,所有和1进行按位&操作,肯定是1,可判断出来是奇数,如果结果为0那么为偶数
0x00010000
&
0x00000001
Int a = 16;
Int b= 25;
If(a & 1)
奇数
Else
偶数
边栏推荐
- [MP error] MP: 'getbasemappe serviceimpl' claims
- How to set some app application icons on the iPhone Apple phone that you don't want others to see? How to hide the app application settings on the mobile desktop so that they can be used normally afte
- Grpc frequently asked questions
- Multi merchant mall system with relatively clean code
- Heuristic merging simple problem on tree
- 3715. Minimum number of exchanges
- DJ-131/60C电压继电器
- ERROR:bokeh.core.validation. check:E-1001 (BAD_COLUMN_NAME)
- Chrome plug-in debugging
- 听说crmeb多商户增加了种草功能?
猜你喜欢
随机推荐
ERROR:bokeh.core.validation.check:E-1001 (BAD_COLUMN_NAME)
软件测试的流程规范有哪些?具体要怎么做?
JY-7GA/1电压继电器
Gfpgan blurred photo repair artifact
3540. Binary search tree
Leetcode - random set, longest multiclass subsequence
crmeb标准版4.4都会增加哪些功能
7/13(水塘抽样)
游戏测试的概念是什么?测试方法和流程有哪些?
Problems encountered by pyppeter
Pycharm - output exception of program run and default comment of added function
Classic Dijkstra and the longest way
Hjs-de1/2 time relay
Jwy-32b voltage relay
mysql 8.0常用(持续更新)
R introduction example details
Idea debugging burpsuit plug-in
crmeb标准版附带的客服系统
.net core 2.2 版本跨域配置
Crmeb Standard Edition window+phpstudy8 installation tutorial (II)







