This is the code I've tried:
int num = ~0;
System.out.print(num);
Output: -1
From what I understand, ~
inverts the bits. So, 0000 0000
would become 1111 1111
. How is this -1
? I realize that this is a very basic question that involves two's complement, but I'm not able to figure it out.