Created
September 14, 2015 18:32
-
-
Save toboqus/13b635b8dd1b33179218 to your computer and use it in GitHub Desktop.
Russian peasant algorithm
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
public class RussianPeasant { | |
public Static int product(int a, int b){ | |
int x = a; | |
int y = b; | |
int z = 0; | |
while(x > 0){ | |
if(x%2 == 1) z += y; | |
x = x >> 1; | |
y = y << 1; | |
} | |
return z; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment