当前位置:网站首页>位运算符与逻辑运算符的区别
位运算符与逻辑运算符的区别
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 underlying mechanism of the class
![[Student Graduation Project] Design and Implementation of the Website Based on the Web Student Information Management System (13 pages)](/img/86/9c9a2541f2b7089ae47e9832fffdb3.png)
[Student Graduation Project] Design and Implementation of the Website Based on the Web Student Information Management System (13 pages)

多线程查询结果,添加List集合

逆向理论知识4

Excel Paint
![[Surveying] Quick Summary - Excerpt from Gaoshu Gang](/img/35/e5c5349b8d4ccf9203c432a9aaee7b.png)
[Surveying] Quick Summary - Excerpt from Gaoshu Gang

【Transfer】What is etcd

【学生毕业设计】基于web学生信息管理系统网站的设计与实现(13个页面)

WPF中DataContext作用

8.04 Day35-----MVC three-tier architecture
随机推荐
1.3 mysql批量插入数据
coppercam入门手册[6]
Flutter学习-开篇
dedecms报错The each() function is deprecated
for..in和for..of的区别
The role of DataContext in WPF
Flutter real machine running and simulator running
Reverse theory knowledge 4
[Surveying] Quick Summary - Excerpt from Gaoshu Gang
Mvi架构浅析
span标签和p标签的区别
2022 Hangzhou Electric Multi-School 1st Session 01
The difference between span tag and p
How can Flutter parent and child components receive click events
算法---一和零(Kotlin)
Shell(4) Conditional Control Statement
【cesium】Load and locate 3D Tileset
【cesium】加载并定位 3D Tileset
Analysis of Mvi Architecture
Dashboard Display | DataEase Look at China: Data Presents China's Capital Market