Russian Peasant Multiplication

Saturday 30 August 2014
Following is an algorithm to multiply two numbers without using the multiplication operator.Although there are other ways of doing this like using bit-wise operators this method is particularly mentioned because it is named the Russian Peasant Multiplication.

int res = 0;
while(b>0){
    if(b&1==0)
        res = res + a;
    a = a << 1;
    b = b >> 1;
}
return res; 

Copyright @ 2013 code-craft. Designed by Templateism | MyBloggerLab