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

边栏推荐
- dedecms error The each() function is deprecated
- Detailed Explanation of Redis Sentinel Mode Configuration File
- 2023 International Conference on Information and Communication Engineering (JCICE 2023)
- Mysql5.7 二进制 部署
- Analysis of Mvi Architecture
- A blog clears the Redis technology stack
- 『递归』递归概念与典型实例
- 服务器磁盘阵列
- 【无标题】
- Algorithms - ones and zeros (Kotlin)
猜你喜欢

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

The solution to the failure to read channel information when dedecms generates a message in the background

Day019 方法重写与相关类的介绍

Using QR codes to solve fixed asset management challenges

server disk array

Multi-threaded query results, add List collection

The difference between span tag and p

The mall background management system based on Web design and implementation

The role of DataContext in WPF

mutillidae download and installation
随机推荐
OFDM Lecture 16 5 -Discrete Convolution, ISI and ICI on DMT/OFDM Systems
After controlling the export file in MySQL, it becomes \N. Is there any solution?
How does the Flutter TapGestureRecognizer work
Difference between for..in and for..of
Day019 Method overriding and introduction of related classes
In the hot summer, teach you to use Xiaomi smart home accessories + Raspberry Pi 4 to connect to Apple HomeKit
【cesium】Load and locate 3D Tileset
Requests库部署与常用函数讲解
【Transfer】What is etcd
Structured Light 3D Reconstruction (2) Line Structured Light 3D Reconstruction
【学习笔记之菜Dog学C】动态内存管理之经典笔试题
【cesium】加载并定位 3D Tileset
LAB Semaphore Implementation Details
Mysql5.7 二进制 部署
coppercam入门手册[6]
入口点注入
Qt produces 18 frames of Cupid to express his love, is it your Cupid!!!
结构光三维重建(二)线结构光三维重建
Flutter学习三-Flutter基本结构和原理
Error creating bean with name ‘configDataContextRefresher‘ defined in class path resource