Categories
algorithms kotlin

Problem 5.5 from EPI -> Compute X x Y without arithmetic operands

This one is an interesting problem, the difficulty here is to compute a multiplication with only bitwise operations, so how can this be done?
First we need to figure out how many times we need to add y to x, this can be done by checking how many bits of x are 1, and for each we add shifted y to the sum.
There is also a problem of addition, addition is done with simple bit by bit checking and carry out bit.
Check the complete solution here.

Leave a Reply

Your email address will not be published. Required fields are marked *