wood burning stoves 2.0*
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
Author

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.


JSP
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4456
    
    6

Google for twos complement
Or search this fantastic forum
Junilu
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.
Corey


SCJP Tipline, etc.
Rodney Woodruff
Ranch Hand

Joined: Dec 04, 2001
Posts: 80
Try this link. It helped me alot.
http://www.javaranch.com/campfire/StoryBits.jsp


Hope This Helps
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: confused by shift operators