File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Shift operators " Watch "Shift operators " New topic

Shift operators

Parag Kale

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

Joined: Oct 18, 2000
Posts: 4121

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.


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

Joined: Apr 08, 2001
Posts: 25
Ok. Got it now.
I agree. Here's the link:
subject: Shift operators