3v4l.org

run code in 300+ PHP versions simultaneously
<?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));

preferences:
80.56 ms | 402 KiB | 5 Q