Consider:
php > $a = 12; // 1100
php > echo ~$a;
-13
I would expect the inverse of 1100
to be either 0011
(direct) or 11110011
(an entire byte). That would give a result to either 3
or 243
. Whence cometh -13
?
Again, for good measure, another unexpected result of the same type and explanation:
php > $b = 6; // 0110
php > echo ~$b;
-7
Why -7
?