This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes >>> operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark ">>> operator" Watch ">>> operator" New topic

>>> operator

Eugene Lea

Joined: Sep 30, 2002
Posts: 12
int i = Integer.MIN_VALUE;
byte b = Byte.MIN_VALUE;
Why for i output positive value, for b output negative value ?
Alfred Kemety
Ranch Hand

Joined: Aug 14, 2002
Posts: 279
Integer.MIN_VALUE = 80000000
Byte.MIN_VALUE = 80 = 10000000
when applying the >>> to the byte, it first gets promoted to int then get shifted.
after being shifted because of >>>= it gets implecitly casted back to byte so the value gets truncated.
the output of this code should make you understand what happens.

[ October 14, 2002: Message edited by: Alfred Kemety ]

Alfred Raouf - Egypt - SCJP 1.4<br />Kemety.equals(Egyptian) // returns true
It is sorta covered in the JavaRanch Style Guide.
subject: >>> operator