How do we calculate if it is (b<<31) and (b >>31) I would really appreciate if you can explain this to me.
If we're talking about int values, only the five lowest-order bits are used. It's as if the number you're shifting by is &'ed with 31 (0x1F). In this case, 31 & 31 == 31. So, you'll shift left 31 times, with bits falling off into the void on the left hand side as necessary(e.g., 5 << 31 == -2147483648).