This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark ">>> operator" Watch ">>> operator" New topic
Author

>>> operator

Eugene Lea
Greenhorn

Joined: Sep 30, 2002
Posts: 12
int i = Integer.MIN_VALUE;
byte b = Byte.MIN_VALUE;
i>>>=1;
b>>>=1;
System.out.println(i);
System.out.println(b);
output:
1073741824
-64
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
 
Don't get me started about those stupid light bulbs.
 
subject: >>> operator
 
Similar Threads
how counter variable works in jsp
Pre increment of byte and short variables
Doubt in System.out.println code
Array item selection
About default values in array