Question

Is there ever reason to think the >> (signed) and >>> (unsigned) right bit-shift operators in Java would perform differently? I can't detect any difference on my machine.

This is purely an academic question; it's never going to be the bottleneck I'm sure. I know: it's best to write what you mean foremost; use >> for division by 2, for example.

I assume it comes down to which architectures have which operations implemented as an instruction.

Was it helpful?

Solution

No. Your compiler will translate these to bytecode and the JVM will interpret the bytecode for your architecture. I think it is safe to assume that your architecture has an instruction set which includes both operations be done in few clock cycles.

Anyway, there is a difference in the behavior of these operators, so it isn't like you can just interchange them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top