Skip to content

Instantly share code, notes, and snippets.

@LaffinToo
Created December 31, 2011 07:23
Show Gist options
  • Save LaffinToo/1543232 to your computer and use it in GitHub Desktop.
Save LaffinToo/1543232 to your computer and use it in GitHub Desktop.
Bit Twiddling
<?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