Hi there, I wrote a faster implementation of bitwise primitive multiply.
def multiply(x,y):
def add(x,y):
cum = x ^ y
carry = (x & y) << 1
while carry:
cum, carry = cum ^ carry, (cum & carry) << 1
return cum
leftovers = 0
while y:
if y & 1:
leftovers = add(leftovers,x)
x <<= 1
y >>= 1
return leftovers
Any thoughts on my version vs the one in the book? i think the complexity for my add operation is smaller than O(n) but I’m not exactly sure how to quantify/ analyse it, appreciate if someone can help