aspose file tools*
The moose likes Beginning Java and the fly likes Shift operators Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Shift operators " Watch "Shift operators " New topic
Author

Shift operators

Parag Kale
Greenhorn

Joined: Apr 08, 2001
Posts: 25
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

Joined: Oct 18, 2000
Posts: 4121

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


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Parag Kale
Greenhorn

Joined: Apr 08, 2001
Posts: 25
Ok. Got it now.
Thanks.
Regards,
Parag
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Shift operators