Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

bitwise operator

 
amit mandal
Ranch Hand
Posts: 46
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can someone tell me the difference between ">>" and ">>>" with an example? Every time am understanding am getting confused and back to where i started :/
 
Adolfo Eloy
Ranch Hand
Posts: 146
Eclipse IDE Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amit,

What I know is that when using the >> (right shift) the signal won't be considered when the right shift execution.
But when using >>> the signal will be considered, so regarding your value, a signed value will loose the signal.

Take a look at the code and output below:



outputs:

11111111111111111111111111110110
-------------------------------
a >> 2
decimal value: -3
binary value.: 11111111111111111111111111111101
-------------------------------
a >>> 2
decimal value: 1073741821
binary value.: 111111111111111111111111111101
 
Stephan van Hulst
Bartender
Pie
Posts: 6098
71
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure to never use the >>> operator on bytes, char and shorts. It is inherently broken for those data types.
 
amit mandal
Ranch Hand
Posts: 46
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys i understood
 
Bert Bates
author
Sheriff
Posts: 8900
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

Bitwise operators like these are NO LONGER ON THE EXAM !

hth,

Bert
 
amit mandal
Ranch Hand
Posts: 46
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bert Bates wrote:Hi Guys,

Bitwise operators like these are NO LONGER ON THE EXAM !

hth,

Bert


Yes i knew. I just asked for knowledge's sake ;)
thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic