Given two integers. You have to perform multiplication operation between two numbers using bitwise operators.
First line contains two integers separated by space.
Print the resultant value.
Step-i)get the minimum of both the numbers
Step-ii) assign minimum number to num1 and other number to num2
Step-iii)initialize a variable to 0
Step-iv) if and operation between num2 and 1 is 1 add num1 to the variable
Step-v)right shift bits of num1 by one position and left shift bits of num2 by one position
Step-vi) repeat steps iv and v until num2 is greater than 0
Step-vii) return answer
Time Complexity: O(logn) where n is maximum of two numbers
Space Complexity: O(1)
Let us know if you can come up with a better approach, mail us at firstname.lastname@example.org Your approach will be reviewed and posted with credits to you.