当前位置:网站首页>位运算符与逻辑运算符的区别
位运算符与逻辑运算符的区别
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)逻辑运算符存在短路现象,即前面的表达式判断成功时,后面的表达式不会执行。

边栏推荐
- 开发一套高容错分布式系统
- After controlling the export file in MySQL, it becomes \N. Is there any solution?
- [Surveying] Quick Summary - Excerpt from Gaoshu Gang
- Flex layout frog game clearance strategy
- Reverse theory knowledge 4
- Excel画图
- [Student Graduation Project] Design and Implementation of the Website Based on the Web Student Information Management System (13 pages)
- ESP32 485 Illuminance
- Flutter学习5-集成-打包-发布
- The mall background management system based on Web design and implementation
猜你喜欢

Day019 Method overriding and introduction of related classes

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

Structured Light 3D Reconstruction (2) Line Structured Light 3D Reconstruction

Develop a highly fault-tolerant distributed system

shell函数

【cesium】元素高亮显示

flex布局青蛙游戏通关攻略

Basic properties of binary tree + oj problem analysis

结构光三维重建(二)线结构光三维重建

Flutter学习2-dart学习
随机推荐
UVA10827
shell函数
[Nine Lectures on Backpacks - 01 Backpack Problems]
The underlying mechanism of the class
Geek卸载工具
Analysis of Mvi Architecture
Flutter学习三-Flutter基本结构和原理
MySQL基础(一)---基础认知及操作
2022杭电多校第一场01
【cesium】3D Tileset 模型加载并与模型树关联
【cesium】加载并定位 3D Tileset
dedecms报错The each() function is deprecated
LeetCode:1403. 非递增顺序的最小子序列【贪心】
uboot enable debug printing information
Redis哨兵模式配置文件详解
使用二维码解决固定资产管理的难题
u-boot debugging and positioning means
Returned object not currently part of this pool
The solution to the failure to read channel information when dedecms generates a message in the background
延迟加载js方式async与defer区别