Module:Bit

De The Binding of Isaac: Rebirth Wiki
Aller à la navigation Aller à la recherche

La documentation pour ce module peut être créée à 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_frame.args( f ) ) )
end


function p.count( f )
    local arg    = tonumber( w_frame.args( f )[1] ) or 0
    local newarg
    local result = 0
    while arg ~= 0 do
    	newarg = bit32.rshift( arg, 1 )
        result = newarg * 2 == arg and result or result + 1
        arg    = newarg
    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_frame.args( f ) ) )
end


return p