Q:

Multiply a number by 2 using bitwise operation

0

Multiply a number by 2 using bitwise operation

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Left shifting of a data (number) by 1 is equivalent to data*2. In data, every bit is a power of 2, with each shift we are increasing the value of each bit by a factor of 2.

#include <stdio.h>
int main()
{
    unsigned int data = 15; //value of data
    data = data << 1; // equivalent to data * 2
    printf("data = %d\n", data);
    return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Divide a number by 2 using bitwise operation... >>
<< Clear all bits from LSB to ith bit...