Created
December 31, 2011 07:23
-
-
Save LaffinToo/1543232 to your computer and use it in GitHub Desktop.
Bit Twiddling
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 | |
function setbit($flags,$position) | |
{ | |
return $flags|(1<<$position); | |
} | |
function resetbit($flags,$position) | |
{ | |
return $flags&(~(1<<$position)); | |
} | |
function togglebit($flags,$position) | |
{ | |
return $flags^(1<<$position); | |
} | |
function readbit($flags,$position) | |
{ | |
return ($flags|(1<<$position))?1:0; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment