I apologize if the question I’m raising is way too basic, but I really don’t understand this. And I my theoretical background is not software engineering.
Let’s say se are dealing with a Java int, which is 32 bit. So:
2 = 00000000 00000000 00000000 00000010
I understand Tilde of 2 is the bitwise of 2. So:
~2 = 11111111 11111111 11111111 11111101
For which I must find which positive number is the twos complement of this, which is 3, so ~2 = -3
But what I don’t get about all this is…
How does the machine differentiates when 11111111 11111111 11111111 11111101 means -3 And when does it mean -2billion?
I can’t understand this because it seems to violate the injective behavior between bits and numbers.
What am I getting wrong here?