Python位运算实现加法和乘法

Python位运算实现加法和乘法



代码中不出现加号和乘号,实现加法和乘法,似乎没有神马卵用,秀操作,哈哈哈。


def add(a,b):
    if a==0:
        return b
    return add((a&b)<<1,a^b)


def mul(a,b):
    s=0
    while b:
        if b&1:
            s=add(sum,a)
        a=a<<1
        b=b>>1 
    return s





猜你喜欢

转载自blog.csdn.net/moluth/article/details/79253542