Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

>>>

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can somebody explain this with an eg?
The value returned by >>> will never be negative as long as the value of the right operand is not divisible by 32.
I would like to know if there are any chances of getting a negative number when the right operand is divisible by 32.
Thanks
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep, you can get a negative number with >>> when right-hand value is divisible by 32. The reason is that if the left hand value is an int, then you can only shift by 31 places at most. A shift by 32 places does nothing to the value. If you try to shift an int by 33 places than it does a shift by the value 32%33 or 1.
So if you have:
-1 >>> 32 or -1 >>> 64 etc... you will get -1 becuase it is not performing the shift at all. Any other value on the right hand side will make the result a positive.
Bill
 
Ash Rai
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bill. That was nice.
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Ash
As Bill said, you can shift a given integral value by using shift-right-with-zero-fill(>>>). If the right operand is equals 32, then the original value is the result. when the right operand is bigger than 32 but not the integral times of 32, the result is the result of >>>(rOp -32). Maybe the following can help u undertand it:

regds
George
 
Ash Rai
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks George!!!
 
I'm still in control here. LOOK at this tiny ad!
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic