public class sap { static int b; public static void main(String[]args) { b=7; System.out.println("b = 7; ~b = \t\t\t -> " + (~b) ); } } The Binary of 7 is 00000111. after inverting it, it is 11111000. //The output which is coming is -8.Can anybody explain how an output is coming -8?.
There's a great JavaRanch write-up on this, called Cat and Mouse Games with Bits: http://www.javaranch.com/campfire/StoryBits.jsp At the bottom of the page is an applet that shows you exactly what results you'll get with the different bit operators.
Susan
I'm not sure if I approve of this interruption. But this tiny ad checks out:
a bit of art, as a gift, the permaculture playing cards