当前位置:网站首页>位运算的一些操作
位运算的一些操作
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
偶数
边栏推荐
猜你喜欢

In 2022, the average salary of global programmers was released, and China ranked unexpectedly

Crmeb Standard Version window+phpstudy8 installation tutorial (I)

Publish raspberry pie web page with cpolar (apache2 installation test)

MySQL 8.0 common (continuous update)

Ry-d1/1 voltage relay

Chrome plug-in debugging

电压继电器DY-28C

流畅到让人头皮发麻的单商户商城,你用过吗?

Deepfacelab model parameters collection

How Charles installs and uses
随机推荐
DJ-131/60C电压继电器
sql语句的执行流程
3715. Minimum number of exchanges
听说crmeb多商户增加了种草功能?
pyppeteer 遇到的问题
4、主程序和累积中断处理例程实现代码
手把手带你编写一个规范的字符设备驱动
.net core version 2.2 cross domain configuration
Chrome plug-in debugging
Data synchronization of new version
About the reptile thing
Encapsulate the unified return object messageresult
1、开源GPS项目HD-GR GNSS的著作者
Multi merchant mall system with relatively clean code
sql 开发篇一 之 表锁查询及解锁
提速1200倍!MIT开发新一代药物研发AI,吊打老模型
4.8 HD-GR GNSS导航软件源码
Customer service system attached to crmeb Standard Edition
Back compilation failed
Heuristic merging simple problem on tree