Why does this code return -1 ?
$a = 0; echo ~$a;
Isn\'t not suppose to revert the bits ?
That zero is actually being represented by 32 zero bits, as PHP integer types are 32-bit signed integers, and not single bits:
0000 0000 0000 0000 0000 0000 0000 0000
So bitwise NOT flips all of them, resulting in the two's complement of -1 (with the leftmost one representing the sign):
1111 1111 1111 1111 1111 1111 1111 1111