当前位置:网站首页>位运算符与逻辑运算符的区别
位运算符与逻辑运算符的区别
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)逻辑运算符存在短路现象,即前面的表达式判断成功时,后面的表达式不会执行。
边栏推荐
- 二叉树基本性质+oj题解析
- University Physics---Particle Kinematics
- 【转】什么是etcd
- 【软考 系统架构设计师】软件架构设计③ 特定领域软件架构(DSSA)
- Flutter真机运行及模拟器运行
- software management rpm
- The solution to the failure to read channel information when dedecms generates a message in the background
- Structured Light 3D Reconstruction (2) Line Structured Light 3D Reconstruction
- Day019 Method overriding and introduction of related classes
- 结构光三维重建(二)线结构光三维重建
猜你喜欢
Dephi reverse tool Dede exports function name MAP and imports it into IDA
Excel画图
Error creating bean with name ‘configDataContextRefresher‘ defined in class path resource
Day019 Method overriding and introduction of related classes
Redis哨兵模式配置文件详解
The mall background management system based on Web design and implementation
jvm three heap and stack
for..in和for..of的区别
The underlying mechanism of the class
OFDM Lecture 16 5 -Discrete Convolution, ISI and ICI on DMT/OFDM Systems
随机推荐
jvm three heap and stack
Application status of digital twin technology in power system
Flutter学习4-基本UI组件
Dashboard Display | DataEase Look at China: Data Presents China's Capital Market
入口点注入
Flutter learning three-Flutter basic structure and principle
【学生毕业设计】基于web学生信息管理系统网站的设计与实现(13个页面)
Returned object not currently part of this pool
仪表板展示 | DataEase看中国:数据呈现中国资本市场
LeetCode:1403. 非递增顺序的最小子序列【贪心】
software management rpm
[Decoding tools] Some online tools for Bitcoin
Flex layout frog game clearance strategy
【cesium】Load and locate 3D Tileset
server disk array
UVA10827
服务器磁盘阵列
UVA10827
uboot enable debug printing information
[Surveying] Quick Summary - Excerpt from Gaoshu Gang