Q:

Divide a number by 2 using bitwise operation

0

Divide 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

Right shifting of a data (number) by 1 is equivalent to data/2. In data, every bit is a power of 2, with each right shift we are reducing the value of each bit by a factor of 2.

#include <stdio.h>
int main()
{
    unsigned int data = 16; //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)

Multiply a given Integer with 3.5 using bitwise op... >>
<< Multiply a number by 2 using bitwise operation...