bit32.lua
Opened this issue · 0 comments
DnsIs commented
Although many years have passed, I will say that bit32.lshift and bit32.rshift are not working correctly.
We won't go into details, but here are some better implementations:
local function ror(num, shift)
local x32 = 2 ^ 32 - 1;
num = num & x32;
x = shift % 32;
n1 = num >> x;
n2 = num << (32 - x) & x32;
return string.format("%u", (n1 | n2));
end
local function rol(num, shift)
local x32 = 2 ^ 32 - 1;
num = num & x32;
x = shift % 32;
n1 = (num << x) & x32;
n2 = num >> (32 - x);
return string.format("%u", (n1 | n2));
end