Friday 27 July 2012

Multiply two intergers using bitwise operator

#include<stdio.h>

void main()
{
    int a,b,result;

    printf("Enter the numbers to be multiplied :\n");

    scanf("%d%d",&a,&b);

    result=0;
    while(b != 0)
    {
        if (b&0x01)
        {
            result=result+a;
        }
        a<<=1;
        b>>=1;
    }
    printf("Result:%d",result);
}

No comments:

Post a Comment