Monday, February 25, 2013

How could you multiply 2 Integers using bit-wise operators?


#include<stdio.h>

main()
{
int a, b, num1, num2, result=0;  
printf("\nEnter the numbers to be multiplied :");
scanf("%d%d",&num1,&num2);
a=num1;
b=num2;
while(num2 != 0)            
{
if (num2 & 01)              
               {
        result+=num1;  
               }
num1<<=1;                
                num2>>=1;                
}
printf("\nMultiplication of %d*%d=%d", a, b, result);
}

No comments :