This week's book giveaway is in the Other Languages forum.We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!

# shift operator

Anonymous
Ranch Hand
Posts: 18944
Has anybody tried shifting an integral number by negative number of places say, 9 >> -2. It does not give any error ?
But it gives some strange result. It seems that signed or unsigned right shift of any integral number by negative number gives 0 but the same with signed left shift gives some strange result. I wonder what's happening here !!!

Marcela Blei
Ranch Hand
Posts: 477

Has anybody tried shifting an integral number by negative number of places say, 9 >> -2. It does not give any error ?

add 32 to the negative value 32 - 2 = 30
Try: 9 << 30 and 9 << -2
They show the same result

[This message has been edited by Marcela Blei (edited July 26, 2000).]

Uvnik Gupta
Ranch Hand
Posts: 32
Hi Marcela,
I couldn't understand how does 32%2 gives 30. It should give 0 as 32 is completely divisible by 2.

Marcela Blei
Ranch Hand
Posts: 477
Sorry, that was confusing! (I edited my first message)
view: http://www.javaranch.com/ubb/Forum24/HTML/002679.html

[This message has been edited by Marcela Blei (edited July 26, 2000).]

Chris Cleverley
Greenhorn
Posts: 22
I got it Marcela. Thanks.
Chris