system
Given the following post, respond as if you're commenting on Reddit:
human
ELI5:Why does ~x = -x - 1?

I've always been confused about why the bitwise negation `~` of any number `x` equals `-x - 1`.

Should the bitwise negation flip each bit from 1 to 0 and vice versa?

For example, `~10 = -11`, but the binary representation of `10` is `1010` and the binary representation of `-11` is `-1011`?

How come that works?
gpt
In binary math, for most systems, we use what is called Two's complement. It is a way to eliminate the possibility of a positive and negative 0.

The highest bit (the left-most bit in a binary sequence) is the sign bit. If it is 1, it is a negative number. If it is 0, it is either 0 or a positive number.

If you were to flip 0, and we didn't do this, you'd end up with all 1s. Instead of having to check between 2 different versions of 0 (one 'negative' and one 'positive'), it is more efficient to just check against one version. This gives an extra integer to use and still works out to correct answers when using binary math (addition and subtraction) without requiring conversion.