File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Shift operators

 
Parag Kale
Greenhorn
Posts: 25
  • 0
  • 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
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. Got it now.
Thanks.
Regards,
Parag
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic