Abfahrtsanzeiger Display Basic Library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
libmonoformat/php/monoformat_bithelpers.php

43 lines
808 B

<?php
namespace monoformat {
function isBitSet(int $value, int $bit) {
if ($bit < 0 || $bit >= (PHP_INT_SIZE * 8)) {
return false;
}
$mask = 1 << $bit;
return ($value & $mask) == $mask;
}
function setBit(int &$value, int $bit) {
if ($bit < 0 || $bit >= (PHP_INT_SIZE * 8)) {
return;
}
$mask = 1 << $bit;
$value |= $mask;
}
function unsetBit(int &$value, int $bit) {
if ($bit < 0 || $bit >= (PHP_INT_SIZE * 8)) {
return;
}
$mask = 1 << $bit;
$value &= ~$mask;
}
function maybeSetBit(int &$value, int $bit, int $set) {
if ($bit < 0 || $bit >= (PHP_INT_SIZE * 8)) {
return;
}
$mask = 1 << $bit;
if ($set) {
$value |= $mask;
} else {
$value &= ~$mask;
}
}
} // namespace monoformat
?>