pythonwiegand

What Does >> mean in Python?


Someone sent me this equation but I don't understand what it means.

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

It has to do with converting the binary from a wiegand reader.

Reference


Solution

  • The >> operator in Python is a bitwise right-shift. If your number is 5, then its binary representation is 101. When right-shifted by 1, this becomes 10, or 2. It's basically dividing by 2 and rounding down if the result isn't exact.

    Your example is bitwise-complementing c1, then right-shifting the result by 1 bit, then masking off all but the 24 low-order bits.