Created
February 28, 2018 19:29
-
-
Save melwinalm/4f5d19873679c5df13846e2aad4e041d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def multiply(a,b): | |
if a > b: | |
left = a | |
right = b | |
else: | |
left = b | |
right = a | |
prod = 0 | |
while left > 0: # Loop till you reach 1 | |
if left%2 != 0: # Add the value to product variable if the left column value is odd | |
prod = prod + right | |
left = left >> 1 # Right shift | |
right = right << 1 # Left Shift | |
return prod | |
print(multiply(127,68)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment