Alex Rivera | Logout

How do I use the bitwise operator XOR in Lua?

Asked 2011-05-12T12:02:50.513
25

How can I implement bitwise operators in Lua language?
Specifically, I need a XOR operator/method.

Edit
Report

2 Answers

12

In Lua 5.2, you can use the bit32.bxor function.

answered 2011-05-16T18:07:59.653
5

If you're needing an efficient way to do bitwise shifts, I wrote an article about that a while ago. Here's some functions which wrap the technique:

function lshift(x, by)
  return x * 2 ^ by
end

function rshift(x, by)
  return math.floor(x / 2 ^ by)
end
answered 2011-05-17T04:30:06.487

Your Answer