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
• Tim Cooke
• Devaka Cooray
• Ron McLeod
• Jeanne Boyarsky
Sheriffs:
• Liutauras Vilda
• paul wheaton
• Junilu Lacar
Saloon Keepers:
• Tim Moores
• Stephan van Hulst
• Piet Souris
• Carey Brown
• Tim Holloway
Bartenders:
• Martijn Verburg
• Frits Walraven
• Himai Minh

# shift operators

Greenhorn
Posts: 27
• Number of slices to send:
Optional 'thank-you' note:
I'm having a hard time with this topic; more specifically, I'm having a hard time doing these problems quickly. Where can I get more practice on this topic?
Thanks.
Mansi

Ranch Hand
Posts: 75
• Number of slices to send:
Optional 'thank-you' note:
consult ur textbook. preferrably k&b, then do some practise @ www.javacertificate.com.
cheers

Ranch Hand
Posts: 504
• Number of slices to send:
Optional 'thank-you' note:
Hi Mansi,
It helps to practice with converting decimals of all bases into binary first of all. Hope, you know ways of converting numbers. Most used numbers like -128,127,-1, Integer.MAX_VALUE and Integer.MIN_VALUE is nice to learn by heart, at least, their hex and binary representation. When doing signed right shift, you divide the original number by 2 to the power of bits to shift and take the int portion, unless that number is multiple of 32 (or 64 for long numbers). 51>>2 = 0011 0011 >> 2= 0000 1100 = 12
Left shift - you multiply the original number by 2 to the power of shifted bits (unless it's multiple of 32 or 64). Unsigned right shift is a bit trickier for negative numbers - it may result in big positive numbers:

The result is 2147483647.