Skip to content

Instantly share code, notes, and snippets.

@flaviors200
Last active May 28, 2019 23:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flaviors200/472666e548da557016ca37fe69081e15 to your computer and use it in GitHub Desktop.
Save flaviors200/472666e548da557016ca37fe69081e15 to your computer and use it in GitHub Desktop.
Bitwise operators
<?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