东郭写的左移位操作

function  bit._lshift(a,n)
    local op1 = bit._d2b(a) 
    local r = bit._d2b(0) 
    if n < 32 and n > 0 then 
    for i = n,31 do 
        r[i-n+1] = op1[i+1] 
        end 
    end 
    local ret = 0 
    if r[1]==1 then
        op1 = bit._not(r)
        ret = bit._b2d(op1) + 2
        ret = 0 - ret;
    else
        ret = bit._b2d(r) 
    end

    return ret 
end

你可能感兴趣的:(东郭写的左移位操作)