逻辑与按位 [英] Logical vs bitwise

查看:63
本文介绍了逻辑与按位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

逻辑运算符andor和按位模拟物&|在用法上有什么区别?各种解决方案的效率是否存在差异?

What the different between logical operators and, or and bitwise analogs &, | in usage? Is there any difference in efficiency in various solutions?

推荐答案

逻辑运算符对逻辑值进行运算,而按位运算符对整数位进行运算.停止考虑性能,并按其预期目的使用它们.

Logical operators operate on logical values, while bitwise operators operate on integer bits. Stop thinking about performance, and use them for they're meant for.

if x and y: # logical operation
   ...
z = z & 0xFF # bitwise operation

这篇关于逻辑与按位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆