Big Moose Saloon
 Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies Register / Login Win a copy of Head First Android this week in the Android forum!

# 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?

subject: bitwise calculation