Last active
May 28, 2019 23:05
-
-
Save flaviors200/472666e548da557016ca37fe69081e15 to your computer and use it in GitHub Desktop.
Bitwise operators
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
<?php | |
$x = 127; // 1111111 | |
$y = 85; // 1010101 | |
var_dump(decbin($x & $y)); // Output: string(7) 1010101 | |
var_dump(decbin($x | $y)); // Output: string(7) 1111111 | |
var_dump(decbin($x ^ $y)); // Output: string(6) 101010 | |
var_dump(decbin(~ $x)); // Output: string(64) 1111111111111111111111111111111111111111111111111111111110000000 | |
var_dump(decbin($x << 1)); // Output: string(8) 11111110 | |
var_dump(decbin($y >> 2)); // Output: string(5) 10101 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment