naraku9333

Simple binary multiplier

Dec 6th, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.24 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int bin_mult(int a, int b)
  4. {
  5.     int res = 0;
  6.     while(b)
  7.     {
  8.         if (b & 1) res += a;
  9.         a <<= 1;
  10.         b >>= 1;
  11.     }
  12.     return res;
  13. }
  14.  
  15. int main()
  16. {
  17.     std::cout << bin_mult(100, 100) << std::endl;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment