Multiplication of two numbers with shift operator | CPP program to find multiplication of two number without use of multiplication operator ; Function for multiplication ; check for set bit and left shift n , count times ; increment of place value ( count ) ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int multiply ( int n , int m ) { int ans = 0 , count = 0 ; while ( m ) { if ( m % 2 == 1 ) ans += n << count ; count ++ ; m /= 2 ; } return ans ; } int main ( ) { int n = 20 , m = 13 ; cout << multiply ( n , m ) ; return 0 ; }