• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

shift operator

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it Marcela. Thanks.
Chris
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic