bit = {data32={}} for i = , do
bit.data32[i] = ^(-i)
end function bit:d2b( arg )
local num = tonumber( arg )
local tr = {} if num ~= nil then
print("num = "..num)
if num >= then
for i = , do
if num >= bit.data32[i] then
num = num - bit.data32[i]
tr[i] =
else
tr[i] =
end
end
return tr
else
return tr
end
else
return tr
end
end function judge0or1( arg )
if arg == nil then
return
end for i = , #arg do
if arg[i] ~= or arg[i] ~= then
return
end
end return
end function bit:b2d( arg )
local num = if arg ~= nil then
for i = , do
if arg[i] == then
num = num + bit.data32[i]
elseif arg[i] ~= then
return num
end
end
return num
else
return num
end
end function bit:prit( arg )
local tr = bit:d2b(arg) if tr == nil then
print("o")
return
end
for i = , #tr do
print(tr[i])
end
end function bit:lsh( arg , n )
local num = tonumber( arg )
local n1 = tonumber( n )
local rr = bit:d2b()
local tr = {} if num == nil then
return
end if n1 == nil then
return
end local num1 = bit:d2b ( arg ) if n1 < and n1 > then
for i = , - n1 do
num1[i] = num1[i+n1]
num1[i+n1] =
end
rr = num1
end return bit:b2d(rr)
end function bit:rsh( arg , n )
local num = tonumber( arg )
local n1 = tonumber( n )
local rr = bit:d2b()
local tr = {} if num == nil then
return
end if num < then
return
end if n1 == nil then
return
end local num1 = bit:d2b ( arg ) if n1 < and n1 > then
for i = - n1, , - do
num1[i+n1] = num1[i]
num1[i] =
end
rr = num1
end return bit:b2d(rr)
end function bit:aand( arg1 , arg2 )
local num1 = tonumber( arg1 )
local num2 = tonumber( arg2 ) if num1 == nil then
return
end if num2 == nil then
return
end local tr1 = bit:d2b ( num1 )
local tr2 = bit:d2b ( num2 )
local tr3 ={} for i = , do
if tr1[i] == and tr2[i] == then
tr3[i] =
else
tr3[i] =
end
end
return bit:b2d(tr3)
end function bit:oor( arg1 , arg2 )
local num1 = tonumber( arg1 )
local num2 = tonumber( arg2 ) if num1 == nil then
return
end if num2 == nil then
return
end local tr1 = bit:d2b ( num1 )
local tr2 = bit:d2b ( num2 )
local tr3 ={} for i = , do
if tr1[i] == and tr2[i] == then
tr3[i] =
else
tr3[i] =
end
end
return bit:b2d(tr3)
end