programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Ron McLeod
• Junilu Lacar
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• Jeanne Boyarsky
• Rob Spoor
• Bear Bibeault
Saloon Keepers:
• Tim Moores
• Tim Holloway
• Piet Souris
• Carey Brown
• Stephan van Hulst
Bartenders:
• Frits Walraven
• fred rosenberger
• salvin francis

# shift operators

Ranch Hand
Posts: 86
• Number of slices to send:
Optional 'thank-you' note:
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

Ranch Hand
Posts: 7729
• Number of slices to send:
Optional 'thank-you' note:
Have a look at Corey's TipLine Article on shift operations.

Ranch Hand
Posts: 195
• Number of slices to send:
Optional 'thank-you' note:

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.

 You showed up just in time for the waffles! And this tiny ad: Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
Similar Threads