File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

bit shifting

 
Francis Palattao
Ranch Hand
Posts: 91
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Joe Borderi
Ranch Hand
Posts: 151
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try running this code:
 
Ray Stojonic
Ranch Hand
Posts: 326
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic