File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

shift operators

 
rajaraman navaneethan
Ranch Hand
Posts: 86
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic