This week's book giveaway is in the Other Languages forum.We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
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:
• Tim Cooke
• Campbell Ritchie
• Ron McLeod
• Liutauras Vilda
• Jeanne Boyarsky
Sheriffs:
• Junilu Lacar
• Rob Spoor
• Paul Clapham
Saloon Keepers:
• Tim Holloway
• Tim Moores
• Jesse Silverman
• Stephan van Hulst
• Carey Brown
Bartenders:
• Al Hobbs
• Piet Souris
• Frits Walraven

# Reg. >>

Ranch Hand
Posts: 327
• Number of slices to send:
Optional 'thank-you' note:
For >> the operand n by s times we can get result as :
n>>s = n / 2 ^ s
Now this works fine for even numbers
eg : 16 >> 2 = 16 / 4 = 2
But if n is odd number then how do i get the result ?

Ranch Hand
Posts: 153
• Number of slices to send:
Optional 'thank-you' note:
IMHO it is better to convert the given number to its binary format & do shift oprn.
Also, what I have learnt from this site is, that in JCP they wont ask very big numbers to shift it right/left and confuse the candidate.
It is fine if we have grasped the concept and apply it correctly.
HTH
tvs sundaram

Ranch Hand
Posts: 90
• Number of slices to send:
Optional 'thank-you' note:
Hello Angella,
Your formula is correct and it also works with odd numbers.Suppose you have:
17>>2 it will give you 2 bcoz in actual calculations 17/4 is 2.5 but when you represent it in int the result will be 2.
I hope it will help.