go****@yahoo.co m wrote:

>

.... snip ...

>

You are talking about specifically "<< as in (1<<...)" not ">as

in a[i>>SHIFT]"? I tried both versions (Bill Pursell & Jon Bentley),

neither of them handles minus numbers correctly. So what is behind

your hint?

>From N869:

6.5.7 Bitwise shift operators

Syntax

[#1]

shift-expr:

additive-expr

shift-expr << additive-expr

shift-expr >additive-expr

Constraints

[#2] Each of the operands shall have integer type.

Semantics

.... snip ...

[#4] The result of E1 << E2 is E1 left-shifted E2 bit

positions; vacated bits are filled with zeros. If E1 has an

unsigned type, the value of the result is E1+2E2, reduced

modulo one more than the maximum value representable in the

result type. If E1 has a signed type and nonnegative value,

and E1+2E2 is representable in the result type, then that is

the resulting value; otherwise, the behavior is undefined.

[#5] The result of E1 > E2 is E1 right-shifted E2 bit

positions. If E1 has an unsigned type or if E1 has a signed

type and a nonnegative value, the value of the result is the

integral part of the quotient of E1 divided by the quantity,

2 raised to the power E2. If E1 has a signed type and a

negative value, the resulting value is implementation-

defined.

i.e. for negative values the results are not portable. So don't do

that. The phrase "2E2" above is a result of the conversion to

text, and means 2 to the E2 power.

--

"The most amazing achievement of the computer software industry

is its continuing cancellation of the steady and staggering

gains made by the computer hardware industry..." - Petroski

--

Posted via a free Usenet account from

http://www.teranews.com