File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes bit shifting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "bit shifting" Watch "bit shifting" New topic
Author

bit shifting

Francis Palattao
Ranch Hand

Joined: Sep 22, 2004
Posts: 91
I thought that using >>> always results in a positive.

For this example it doesn't

byte b = -13;
b >>>= 1;
System.out.println(b);

Answer is -7


SCJP 1.4 <br />SCWCD 1.4 (preparing)<br />SCBCD 1.3 (coming soon)
Joe Borderi
Ranch Hand

Joined: Oct 23, 2004
Posts: 151
Try running this code:
Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326
b is a byte, but the >>>= works on ints, so b is promoted to an int for the operation, then the result is implicitly narrowed back to a byte:
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: bit shifting