Home > front end >  Python equivalent of lua bit32.bxor
Python equivalent of lua bit32.bxor

Time:01-01

I am trying to "convert" a lua script into a python script, but the lua script seems to have a library named bit32, and of which it uses the bxor function. Is there any python equivalent of the bit32.bxor function?

I have searched multiple times on stackoverflow and google for what the equivalent is, but i didn't find any. Maybe I'm just searching the wrong stuff...

CodePudding user response:

Is the script trying to calculate Exclusive OR of 2 integers ? if so you can use the bitwise operator ^

>>>8 ^ 16
24

CodePudding user response:

You can use the ^ operator to perform bitwise exclusive XOR.

result = 10 ^ 20 ^ 30 ^ 40
print(result)  # Output: 50

CodePudding user response:

Python provides bitwise XOR using the bitwise operator ^. However, you can use a function if you want, using the operator.xor(a, b) function.

You can also use NumPy's bitwise XOR function as an equivalent.

  • Related