Why bitwise operation (~0);
prints -1 ? In binary , not 0 should be 1 . why ?
~
is a bitwise operator.
~0 = 1 which is -1 in 2's complement form
http://en.wikipedia.org/wiki/Two's_complement
Some numbers in two's complement form and their bit-wise not ~
(just below them):
0 1 1 1 1 1 1 1 = 127
1 0 0 0 0 0 0 0 = −1280 1 1 1 1 1 1 0 = 126
1 0 0 0 0 0 0 1 = −1271 1 1 1 1 1 1 1 = −1
0 0 0 0 0 0 0 0 = 01 1 1 1 1 1 1 0 = −2
0 0 0 0 0 0 0 1 = 11 0 0 0 0 0 0 1 = −127
0 1 1 1 1 1 1 0 = 1261 0 0 0 0 0 0 0 = −128
0 1 1 1 1 1 1 1 = 127