• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

operator

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[
class Operators
{
public static void main(String [] args)
{
long a = 15;
a = a >> 32;
System.out.println(" a " + a);

}
]
The output is 0 which is understandable if a would have been an int but since it is a long it should get a value of 0 if the expression would have been something like a >> 64;
please explain thanks!
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
32 (decimal) = 100000 (binary). Take low 6 bits of that because we have a long as operand to be shifted. That gives a shift of 32.
Now,
15 >> 1 is 7
15 >> 2 is 3
15 >> 3 is 1
15 >> 4 is 0
... the rest you can work out for yourself.
[ September 20, 2002: Message edited by: Barry Gaunt ]
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if a had been an int then a >> 32 does nothing and a = 15
 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Shubh:
Decimal 15 (long)= 0000,..................,1111 (64 bits)
If you right shift this binary 32 places, you will have all zeros. That is why a becomes 0.
[ September 20, 2002: Message edited by: Barkat Mardhani ]
 
I think I'll just lie down here for a second. And ponder this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic