This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

shift operators

 
rajaraman navaneethan
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at Corey's TipLine Article on shift operations.
 
Joe Sondow
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic