Advertisement
CryptoJones

Russian Peasant Algoritm C#

Jul 31st, 2017
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.48 KB | None | 0 0
  1.         public static int RussianPeasantAlgorithm(int a, int b){
  2.             int z = 0;
  3.             while (a > 0){
  4.                     if (a % 2 == 1){ z = z + b;}
  5.                 b = b << 1;
  6.                 a = a >> 1;
  7.             }
  8.             return z;
  9.         }
  10.  
  11.         public static int NormalMultiplication(int a, int b){
  12.             int z = 0;
  13.             while (a > 0){
  14.                 z = z + b;
  15.                 a = a - 1;
  16.             }
  17.             return z;
  18.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement