-1

有人给我发了这个方程,但我不明白它是什么意思。

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

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

参考

4

2 回答 2

4

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

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

于 2016-05-31T02:23:09.933 回答
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

~运算符执行二进制补码

例子:

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
于 2016-05-31T02:38:34.380 回答