aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes shift operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "shift operator" Watch "shift operator" New topic
Author

shift operator

Anonymous
Ranch Hand

Joined: Nov 22, 2008
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

Joined: Jun 28, 2000
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

Joined: Jul 24, 2000
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

Joined: Jun 28, 2000
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

Joined: Mar 09, 2007
Posts: 22
I got it Marcela. Thanks.
Chris
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: shift operator