• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Shift operators

 
Parag Kale
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What will be the output of the following ?

The answer is given as -1. How is that ?
(edited by Cindy to complete the formatting)


[This message has been edited by Cindy Glass (edited April 12, 2001).]
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Parag,
This is because an int is a 32-bit value, and because the >> operator propegates the high-order bit as it shifts back. Here is a breakdown of what is happening.

HTH,
-Nate
 
Parag Kale
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. Got it now.
Thanks.
Regards,
Parag
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic