Created
January 10, 2015 11:39
-
-
Save abidibo/ee6027384d25a19b86d4 to your computer and use it in GitHub Desktop.
get integer complement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getIntegerComplement( $n) { | |
$n = (int) $n; | |
$mask = bindec(str_repeat('1', strlen(decbin($n)))); | |
$val = $n ^ $mask; | |
return $val; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment