aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes bitwise calculation Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "bitwise calculation" Watch "bitwise calculation" New topic
Author

bitwise calculation

liqiang yang
Ranch Hand

Joined: Jan 20, 2008
Posts: 92
Can anybody figure this out?

int a = -8;
int b = ~ -33;
a>>>=b;
System.out.println(a);


DY.
SCJP 5.0 (100%), SCWCD 5.0 (79%), SCBCD 5.0 (preparing...)
Patricia Samuel
Ranch Hand

Joined: Sep 12, 2007
Posts: 300
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

Joined: Sep 12, 2007
Posts: 300
one more thing since operator >>> then output must be positive .

so it will be 8 instead of -8.
liqiang yang
Ranch Hand

Joined: Jan 20, 2008
Posts: 92
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

Joined: Dec 29, 2007
Posts: 129
Can we expect topics on bitwise operators in the exam?
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: bitwise calculation
 
Similar Threads
Evaluation of nested loops
Shift Right Operator>>
Question from RHE book
Need help with a++/b-- expression
array doubt: a [ (a = b)[3] ]