Why in Java (high + low) / 2 is wrong but (high + low) >>> 1 is not?

In short, (high + low) >>> 1 is a trick that uses the unused sign-bit to perform a correct average of non-negative numbers. Under the assumption that high and low are both non-negative, we know for sure that the upper-most bit (the sign-bit) is zero. So both high and low are in fact 31-bit integers. … Read more