1

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...

River
  • 47
  • 7

3 Answers3

1

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

>>>8 ^ 16
24
zaki98
  • 1,048
  • 8
  • 13
1

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

result = 10 ^ 20 ^ 30 ^ 40
print(result)  # Output: 40
tomerar
  • 805
  • 5
  • 10
1

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.

kkmonlee
  • 379
  • 2
  • 16