File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

bitwise calculation

 
liqiang yang
Ranch Hand
Posts: 92
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody figure this out?

int a = -8;
int b = ~ -33;
a>>>=b;
System.out.println(a);
 
Patricia Samuel
Ranch Hand
Posts: 300
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Output will be -8.

a=-8;
b =~-33
means ~x= -x-1 sot ~-33 will be -(-33)-1 = 32;

a>>>=b -8>>>=32
since we are operating on int 32 (32%32 = 0) hence -8>>>=0

-8/2 raise 0
-8/1 = -8

Please make me correct if i am wrong.

Thanks
 
Patricia Samuel
Ranch Hand
Posts: 300
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one more thing since operator >>> then output must be positive .

so it will be 8 instead of -8.
 
liqiang yang
Ranch Hand
Posts: 92
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Patricia! You did a great job.

I put the piece of code in the program and print the result is -8.
 
Dean Jones
Ranch Hand
Posts: 129
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we expect topics on bitwise operators in the exam?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic