当前位置:网站首页>位运算符与逻辑运算符的区别
位运算符与逻辑运算符的区别
2022-08-05 05:12:00 【Xmn_】
位运算符包含四种'&' ,' ~' , '| ', '^'。
位运算是将数据先转换为二进制补码形式,在逐渐按位计算。其中
"~"为“按位非”运算符,规则:遇1则0,遇0则1。
"&"为“按位与”运算符,规则:全1则1,否则为0。
"^"为“按位异或”运算符,规则:相同为0,不同为1。
"|"为“按位或”运算符,规则:全0则0,否则为1。如:
计算 3|6=x
3 0011
6 | 0110
x 0111=7
所以3|6=7。
注意:
按位异或运算是可逆的,即如果对某个数据a进行两次相同的异或运算,则结果会还原为a,如对数值3进行两次和5的异或运算:
3 ^ 5 = 6;
6 ^ 5 = 3;
逻辑运算符有三种
'&&' ,逻辑与
'||' , 逻辑或
'!',逻辑非
运算规则如下:

总结二者区别
1)逻辑运算符只能针对Boolean类型进行计算,但是位运算是可以对数值进行逻辑运算的。
2)逻辑运算符存在短路现象,即前面的表达式判断成功时,后面的表达式不会执行。

边栏推荐
猜你喜欢

The mall background management system based on Web design and implementation

Wise Force Deleter强制删除工具

Day019 Method overriding and introduction of related classes

Multi-threaded query results, add List collection

使用二维码解决固定资产管理的难题

Difference between for..in and for..of

Flutter学习三-Flutter基本结构和原理

Please write the SparkSQL statement

【Transfer】What is etcd

OFDM 十六讲 5 -Discrete Convolution, ISI and ICI on DMT/OFDM Systems
随机推荐
Day019 方法重写与相关类的介绍
entry point injection
软件管理rpm
Algorithms - ones and zeros (Kotlin)
结构光三维重建(一)条纹结构光三维重建
upload upload pictures to Tencent cloud, how to upload pictures
Flutter学习2-dart学习
1.3 mysql批量插入数据
作业8.4 进程间的通信 管道与信号
span标签和p标签的区别
The mall background management system based on Web design and implementation
Flutter learning - the beginning
C#关于set()和get()方法的理解及使用
jvm 三 之堆与栈
类的底层机制
uboot开启调试打印信息
Judgment statement _switch and case
【cesium】元素高亮显示
How can Flutter parent and child components receive click events
多线程查询结果,添加List集合