This week's book giveaways are in the iOS and Features new in Java 8 forums.
We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line!
See this thread and this one for details.
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


Win a copy of Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

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