- decbin: documentation ( source)
- pow: documentation ( source)
<?php
// Get bit in specified position from right (LSB position = 0)
function getBIT($number, $position) { return ($number >> $position) & 1;}
// Set bit in specified position from right (LSB position = 0)
function setBIT($number, $position, $value) {
if(getBIT($number, $position)){
if(!$value) {
$number -= pow(2, $position);
if($color == "r"){
$setBITcountR++;
//echo "set BITr ";
}
if($color == "g"){
$setBITcountG++;
//echo "set BITg ";
}
if($color == "b"){
$setBITcountB++;
//echo "set BITb ";
}
}
} else {
if($value){
$number += pow(2, $position);
if($color == "r"){
$setBITcountR++;
//echo "set BITr ";
}
if($color == "g"){
$setBITcountG++;
//echo "set BITg ";
}
if($color == "b"){
$setBITcountB++;
//echo "set BITb ";
}
}
}
return $number;
}
echo decbin(setBIT(0b01101001, 3, 0));