How do I use the bitwise operator XOR in Lua?

后端 未结 6 927
一向
一向 2020-12-30 05:38

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

6条回答
  •  庸人自扰
    2020-12-30 05:42

    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
    

提交回复
热议问题