views:

221

answers:

1

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.

+2  A: 

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.

Tim Bender
@Tim Bender: +1... In the x86 world, *">> 1"* since the P4 was only one cycle and since the P6 architecture *">> any"* is only one cycle AFAIK.
Webinator
I think that was my question: do common architectures implement both as an instruction? And yes like I said this only applies in cases where the behavior is identical (nonnegative integers).
Sean Owen