Q:

Multiply a given Integer with 3.5 using bitwise operation

0

Multiply a given Integer with 3.5 using bitwise operation

All Answers

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

We know that multiplication is basically an addition, so we can multiply a given integer (data) with 3.5 using the following operation, (2 *data) + data + (data/2).

#include <stdio.h>
int main()
{
    unsigned int data = 10; //value of data
    data = (data<<1) + data + (data>>1);; // equivalent to data * 3.5
    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)

How to change endianness?... >>
<< Divide a number by 2 using bitwise operation...