如何在Lua中使用按位运算符XOR? [英] How do I use the bitwise operator XOR in Lua?
本文介绍了如何在Lua中使用按位运算符XOR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何用Lua语言实现按位运算符?
具体来说,我需要XOR运算符/方法.
How can I implement bitwise operators in Lua language?
Specifically, I need a XOR operator/method.
推荐答案
在Lua 5.2中,可以使用bit32
库中的函数.
In Lua 5.2, you can use functions in bit32
library.
在Lua 5.3中,bit32
库已过时,因为现在存在本机按位运算符.
In Lua 5.3, bit32
library is obsoleted because there are now native bitwise operators.
print(3 & 5) -- bitwise and
print(3 | 5) -- bitwise or
print(3 ~ 5) -- bitwise xor
print(7 >> 1) -- bitwise right shift
print(7 << 1) -- bitwise left shift
print(~7) -- bitwise not
输出:
1
7
6
3
14
-8
这篇关于如何在Lua中使用按位运算符XOR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文