Skip to content

Latest commit

 

History

History
30 lines (12 loc) · 640 Bytes

Bitwise Operators in Lua.md

File metadata and controls

30 lines (12 loc) · 640 Bytes

Bitwise Operators in Lua

l

Lua supports bitwise operators that operate on integers at the bit level. Here's an example:

local x = 0x0F

local y = 0x10

print(bit.band(x, y)) -- bitwise AND

print(bit.bor(x, y)) -- bitwise OR

print(bit.bxor(x, y)) -- bitwise XOR

print(bit.bnot(x)) -- bitwise NOT

print(bit.lshift(x, 2)) -- bitwise left shift

print(bit.rshift(x, 2)) -- bitwise right shift

In this example, x and y are hexadecimal values that are used to demonstrate the various bitwise operators available in Lua.