• 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

shift operators

 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could any one kindly explain about all shift(<<, >>, >>>) operators with examples or let me know the site where i can find more examples on shift operators. I am preparing for SCJP.
After reading about shift operators i am not able to answer this question.
Q.which of the following expressions results in a positive value in x?
A.int x = -1; x = x >>>5;
B.int x = -1; x = x >>> 32;
C.byte x = -1; x = x >>> 5;
D.int x = -1; x = x >> 5;

Thanks.
 
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Go to the link below for some shift operator exmaples & explanation
http://www.javaprepare.com/notes/operator.html

Originally posted by suresh kamsa:
Could any one kindly explain about all shift(<<, >>, >>>) operators with examples or let me know the site where i can find more examples on shift operators. I am preparing for SCJP.
After reading about shift operators i am not able to answer this question.
Q.which of the following expressions results in a positive value in x?
A.int x = -1; x = x >>>5;
B.int x = -1; x = x >>> 32;
C.byte x = -1; x = x >>> 5;
D.int x = -1; x = x >> 5;

Thanks.


 
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Suresh
here's one I found handy
http://www.jchq.net/tutorial/BitShift.htm
rgds Jim
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by suresh kamsa:
Could any one kindly explain about all shift(<<, >>, >>>) operators with examples or let me know the site where i can find more examples on shift operators. I am preparing for SCJP.
After reading about shift operators i am not able to answer this question.
Q.which of the following expressions results in a positive value in x?
A.int x = -1; x = x >>>5;
B.int x = -1; x = x >>> 32;
C.byte x = -1; x = x >>> 5;
D.int x = -1; x = x >> 5;

Thanks.


Answer A will result in positive value of x. But c will give compiler error. Because x>>>5 will result in int value. Which we are trying to assign to byte. If we do casting that is x=(byte)x>>>5 will result in negative answer. But instead of declaring x as byte, we declare as int we get positive value of x.
In case of >>> operator, negative value of x always result in Positive value.
For further detail refer java specification.Hope it is of some help. Even am preparing for Certification. If anybody else can clear the ideas what I have, it will be of great help
Thanks
Arathi Rajashekar
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My personnal favorite is Cat and Mouse Game with Bits campfire story.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic