mNo edit summary |
m (Undo revision 243486 by Derugon (talk) Really small improvement, not worth the lisibility and maintenance) Tag: Undo |
||
(6 intermediate revisions by the same user not shown) | |||
Line 30: | Line 30: | ||
end |
end |
||
return result |
return result |
||
− | end |
||
− | |||
− | |||
− | function p.masktest( f ) |
||
− | local args = w_frame.args( f ) |
||
− | local result = tonumber( args[1] ) or 0 |
||
− | return '"' .. result .. '"' .. args[1] .. '"' |
||
end |
end |
||
Revision as of 10:10, 3 May 2021
Documentation for this module may be created at Module:Bit/doc
local p = {}
local bit32 = require( 'bit32' )
local w_frame = require( 'module:frame' )
local w_table = require( 'module:table' )
p['and'] = function ( f )
return bit32.band( unpack( w_table.map( w_frame.args( f ), tonumber ) ) )
end
function p.count( f )
local dlc = tonumber( w_frame.args( f )[1] ) or 0
local result = 0
while dlc ~= 0 do
result = result + bit32.band( dlc, 1 )
dlc = bit32.rshift( dlc, 1 )
end
return result
end
function p.mask( f )
local args = w_frame.args( f )
local result = tonumber( args[1] ) or 0
for i = 2, #args do
result = bit32.band( result, bit32.bnot( tonumber( args[i] ) ) )
end
return result
end
p['or'] = function ( f )
return bit32.bor( unpack( w_table.map( w_frame.args( f ), tonumber ) ) )
end
return p