On Sat, 12 Feb 2005 17:03:53 -0500, Ryan wrote:

> Aren't the bitshift operators pointless?

>

> a << b is the same as a = a * 2^b;

> a >> b is the same as a = a % 2^b;

>

> I've run some tests and the bitshift operators aren't any faster than

> their equivalent math expressions.
First of all, they are a lot shorter to write. Also, they are much more

expressive. They speak to you about what happens. So they are

good.

Following your train of thought, you might also argue that we can

throw away all equality operations safe <=

Also, the bit shifts are usually faster then the math expressions. If you

are very lucky, the JVM realizes that it can inline the

Math.pow() calls, and implement the Math.pow() calls as bit shifts. This

is why you get same performance. Try that with any other power, and you'll

take a severe hit.

--

In pioneer days they used oxen for heavy pulling, and when one ox

couldn't budge a log, they didn't try to grow a larger ox. We shouldn't

be trying for bigger computers, but for more systems of computers.

--- Rear Admiral Grace Murray Hopper