Which flags changed between two snapshots?

bitwise_xor sets an output bit exactly when the corresponding input bits differ.

numpy.bitwise_xor in practice

Previous state 1010 and new state 1100 yield change mask 0110. Read the changed positions in both snapshots to distinguish newly enabled flags from disabled ones.

import numpy as np
np.bitwise_xor(10,12)

Result 6

中文

两次状态快照之间哪些位发生了变化?

bitwise_xor 对两侧逐位比较,只有对应位不同时才产生一。

numpy.bitwise_xor 算例

之前是 1010,之后是 1100,变化掩码为 0110。若还要区分打开与关闭,应结合前后快照读取这些变化位。

import numpy as np
np.bitwise_xor(10,12)

结果 6

References / 参考来源

Keep reading / 继续阅读