In Obfuscated C Code Contest 2006. Please explain sykes2.c,
there is a statement "-~i == i+1
because of twos-complement".
Can someone explain why this is the case?
In Obfuscated C Code Contest 2006. Please explain sykes2.c,
there is a statement "-~i == i+1
because of twos-complement".
Can someone explain why this is the case?
-~x
is equal to x+1
because ~x
is equivalent to (0xffffffff-x)
. This is equal to (-1-x)
in 2s complement, so -~x
is -(-1-x) = x+1
.