Two's complement method - generates -(x + 1)
.
for example when JavaScript encounters the Tilde he uses this method:
~5 = -(5+1) = -6.
Fine - lets go deeper.
Now lets talk about the Two's complement method.
5 = 0000 0101
Flip = 1111 1010
add one = 1111 1011
so 1111 1011
is -5
.
how ?
again : flip :
0000 0100
add one :
0000 0101
And so it was -5
.
So how does this settle with ~5=-6
?
where this -6
came from ?