• Post Reply Bookmark Topic Watch Topic
  • New Topic
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
consult ur textbook. preferrably k&b, then do some practise @ www.javacertificate.com.
cheers
 
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
LOOK! OVER THERE! (yoink) your tiny ad is now my tiny ad.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic