programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

bitwise calculation

Ranch Hand
Posts: 92
• Number of slices to send:
Optional 'thank-you' note:
Can anybody figure this out?

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

Ranch Hand
Posts: 300
• Number of slices to send:
Optional 'thank-you' note:
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
• Number of slices to send:
Optional 'thank-you' note:
one more thing since operator >>> then output must be positive .

so it will be 8 instead of -8.

liqiang yang
Ranch Hand
Posts: 92
• Number of slices to send:
Optional 'thank-you' note:
Thanks Patricia! You did a great job.

I put the piece of code in the program and print the result is -8.

Ranch Hand
Posts: 129
• Number of slices to send:
Optional 'thank-you' note:
Can we expect topics on bitwise operators in the exam?