21 lines
634 B
Plaintext
21 lines
634 B
Plaintext
-- Rotate left and right are not built-in but we use the
|
|
-- same 32-bit substitutes as in the Lua 5.3+ example.
|
|
local function rl(x, y) return ((x << y) & 0xffffffff) | (x >> (32 - y)) end
|
|
|
|
local function rr(x, y) return (x >> y) | ((x << (32 - y)) & 0xffffffff) end
|
|
|
|
local function bitwise(x, y)
|
|
print($" x = {x}")
|
|
print($" y = {y}")
|
|
print($" x & y = {x & y}")
|
|
print($" x | y = {x | y}")
|
|
print($" x ~ y = {x ~ y}")
|
|
print($"~x = {~x}")
|
|
print($" x << y = {x << y}")
|
|
print($" x >> y = {x >> y}")
|
|
print($" x rl y = {rl(x, y)}")
|
|
print($" x rr y = {rr(x, y)}")
|
|
end
|
|
|
|
bitwise(10, 2)
|