unexpected result in bit shifting operation

bit-manipulation, java

Solution

It's because of operator precedence.

What you do is the same as

int c=(a>>(2+b))>>2;

You want this :

int c=(a>>2)+(b>>2);

Problem

I think the answer is straight forward but still I am not getting it. ``` byte a=5; int b=10; int c=a>>2+b>>2; System.out.print(c); ``` As `a>>2` is `1` and `b>>2` is `2`, I am expecting output to be `3` but is `0`. What's the reason?

Original source