什么是>>用Python表示?

时间:2016-05-31 02:19:51

标签: python wiegand

有人发给我这个等式,但我不明白这意味着什么。

result = ((~c1) >> 1) & 0x0FFFFFF

它与从韦根阅读器转换二进制文件有关。

Reference

2 个答案:

答案 0 :(得分:3)

Python中的>>运算符是一个按位右移。如果你的数字是5,那么它的二进制表示是101.当右移1时,它变为10或2.它基本上除以2并且如果结果不准确则向下舍入。

您的示例是按位补码c1,然后将结果右移1位,然后屏蔽除24位低位之外的所有位。

答案 1 :(得分:1)

此声明表示:

result =                                # Assign a variable
          ((~c1)                        # Invert all the bits of c1
                 >> 1)                  # Shift all the bits of ~c1 to the right
                        & 0x0FFFFFF;    # Usually a mask, perform an & operator

~运算符执行two's complement

示例:

m = 0b111
x  =   0b11001
~x ==  0b11010      # Performs Two's Complement
x >> 1#0b1100
m ==   0b00111
x ==   0b11001      # Here is the "and" operator. Only 1 and 1 will pass through
x & m #0b    1
相关问题