在LuaForge中提供bitlib可以在lua5.1版本中提高为操作符运算。bitlib通过c语言来实现跨平台位操作符。
Lua functions provided:
bit.bnot(a) returns the one's complement of a
bit.band(w1,...) returns the bitwise and of the w's
bit.bor(w1,...) returns the bitwise or of the w's
bit.bxor(w1,...) returns the bitwise exclusive or of the w's
bit.lshift(a,b) returns a shifted left b places
bit.rshift(a,b) returns a shifted logically right b places
bit.arshift(a,b) returns a shifted arithmetically right b places
bit.mod(a,b) returns the integer remainder of a divided by b
All function arguments should be integers.
The number of bits available for logical operations depends on the data type used to represent Lua numbers;
this is typically 8-byte IEEE floats, which give 53 bits (the size of the mantissa).
在bitlib中所有位操作的参数为整数。
位操作中有效