I just started learning programming in Java. I made a program which calculates the complement of an integer
package demo;
public class unaryOperators {
public static void main(String[] args) {
int numOne = 10;
System.out.println(~numOne);
}
}
The program runs without any errors but the output is not as expected! The output was -11 but as far as I know, Bitwise complement operator complements all the bits of the number.
10 in decimal is 1010
So, ~10 should be 0101 i.e. 5 in decimal!
I referred some articles but cannot find one which in simple for a novice like me to understand.
Thanks for your time!