Here’s the surprisingly simple solution to a fairly challenging problem. I do not understand why PHPs GMP extension does not include a gmp_not() function.
function gmp_not($n) {
# convert to binary string
$n = gmp_strval($n, 2);
# invert each bit, one at a time
for($i = 0; $i < strlen($n); $i++) {
$n[$i] = ~$n[$i];
}
# convert back to decimal
return gmp_strval(gmp_init($n, 2), [...]
After some digging, I found a great way to convert number bases when dealing with arbitrary length integers (esp. integers > 32 bits):
return gmp_strval(gmp_init($n, 2), 10);
This will convert a large base 2 (binary) number to base 10 (decimal).
Check out SNI (multiple SSL vhosts) and mod_proxy_balancer in this great article from Linux Magazine!