Suppose that I want to compute 20*10=200 using only bitwise shifting. This can easily done with
a = 20<<3 // 2^3
b = 20<<1 // 2^1
a + b // Result is 200.
Now, why if I try to do the same thing for division I get a wrong result? For instance if I try to compute 200/10
#include <stdio.h>
int main() {
int value = 200;
int a = value >> 3;
int b = value >> 1;
printf("200/10 is %d\n", (a+b));
return 0;
}
I get a 125? What I'm doing wrong?