File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes confused by shift operators Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "confused by shift operators" Watch "confused by shift operators" New topic

confused by shift operators

SaiPrasad Jukalkar
Ranch Hand

Joined: Feb 20, 2001
Posts: 79
hi ,
i am preparing for scjp exam, i am very much confused with the shift operators,
one of my questions is how to arrive at the binary representation of an negative number.
and example of >>> shift of negative numbers,
i have searched through the javaranch for shift operators, even though i found some good examples, but still am not clear about the concept, i appreciate any help.
thanks in advance.

Junilu Lacar

Joined: Feb 26, 2001
Posts: 6529

Google for twos complement
Or search this fantastic forum
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
As Janilu says, search this forum - there's more information on bit operations and bit shifts and two's complement than you can shake a stick at, ya li'l doggie!
Here's a quick answer:
To get a negative version of a number, take the positive version, flip the bits, and add 1.

The >>> operator (unsigned right shift) shifts all bits to the right and fills the left with 0's.

SCJP Tipline, etc.
Rodney Woodruff
Ranch Hand

Joined: Dec 04, 2001
Posts: 80
Try this link. It helped me alot.

Hope This Helps
I agree. Here's the link:
subject: confused by shift operators
It's not a secret anymore!