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

Interesting >>> operation

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I recently read an interesting article about the >>> operator...
int i = 3;
System.out.println(i >>> 1) ----> prints 1;
System.out.println(i >>> 2) ----> prints 0;
System.out.println(i >>> 3...31) ----> prints 0;
System.out.println(i >>> 32) ----> GUESS WHAT ---> prints 3;
HOW??? i >>> (32%32) = 3. This is based on the variable data type. If is long then i >>> 64 would print 3.
Sivaram.
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any Shift by 32 means no shift at all. This is because a mod 32 operation is performed on the # of bits to be shifted operator and when the # of bits to be shifted is 32, it is actually 32%32 which is 0 bits to be shifted.
HTH
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep, rule of thumb is if the number of bits being shifted is greater than the bit-size of the data type of number being shifted, the actual shift will happen only by the result of reminder division of latter by former.
ie., if x being shifted by y bits and if y is greater than sizeof x ( number of bits, not bytes!! ), then the actual shift will occur only by y%x ( read as y mod x ).
Ajith
 
Look! It's Leonardo da Vinci! And he brought a 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