相关疑难解决方法(0)

按位运算和使用

考虑以下代码:

x = 1        # 0001
x << 2       # Shift left 2 bits: 0100
# Result: 4

x | 2        # Bitwise OR: 0011
# Result: 3

x & 1        # Bitwise AND: 0001
# Result: 1
Run Code Online (Sandbox Code Playgroud)

我可以理解Python(和其他语言)中的算术运算符,但我从来没有完全理解'按位'运算符.在上面的例子中(来自Python书),我理解左移但不是其他两个.

另外,实际使用的是按位运算符?我很欣赏一些例子.

python binary bit-manipulation operators

94
推荐指数
7
解决办法
14万
查看次数

标签 统计

binary ×1

bit-manipulation ×1

operators ×1

python ×1