This week's book giveaway is in the Jobs Discussion forum.We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!See this thread for details.
Big Moose Saloon
 Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies Register / Login Win a copy of Java Interview Guide this week in the Jobs Discussion forum!

# shift operators

rajaraman navaneethan
Ranch Hand

Joined: Feb 26, 2005
Posts: 86
hello friends,
i am preparing for SCJP and i need ur help regarding shift operators.i am not comfortable with shifting negative numbers.can the rule multiplying by 2^number of shifts and divide by 2^number of shifts be applied for negative numbers?
i am also not clear about casting which will be involved in shift operations.will the questions of such type be on the exam?

-192>>2.

can the divide by 2^number of shifts be applied here?

if possible any one of you please send me a list of examples with shift operators that would be sufficient for the exam.

regards
raja
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Have a look at Corey's TipLine Article on shift operations.

Getting someone to think and try something out is much more useful than just telling them the answer.
Joe Sondow
Ranch Hand

Joined: Apr 10, 2005
Posts: 195
Originally posted by rajaraman navaneethan:
-192>>2.

can the divide by 2^number of shifts be applied here?

Let's find out.

2 ^ 2 = 4
-192 / 4 = -48
System.out.println(-192>>2); // prints -48

So for this example the answer is yes.

SCJA 1.0 (98%), SCJP 1.4 (98%)

I agree. Here's the link: http://aspose.com/file-tools

subject: shift operators