Bitwise NOT operator

I was reading this:

and it says:

With a bitwise NOT operator, I would get 6 back. This is because the bitwise NOT flips each bit in the binary representation of 9 separately, so 1001 (9 in binary) becomes 0110, which is 6 in decimal.


trace (~9);

traces: -10

Am I misunderstanding something here? How does this bitwise operator operate exactly??