calabrothers / php-ds-bitmask
PHP 位掩码支持
1.0.0
2020-01-19 22:44 UTC
Requires (Dev)
- phpunit/phpunit: ^8.5
This package is auto-updated.
Last update: 2024-09-20 10:07:24 UTC
README
PHP 位掩码支持
一个支持位掩码操作的字节类。
安装
composer require calabrothers/php-ds-bitmask
测试
composer install
composer test
如何使用
通过构造函数或工厂函数构建对象
$X = new Bitmask(3); // 000...0011
$Y = Bitmask::create(5); // 000...0101
可用函数
让我们考虑经典的三个逻辑运算符
然后基本的 位掩码 对象将提供以下运算符
示例
$X = new Bitmask(3);
echo $X; // Bitmask(64|62|2) [ 0000 0011 ]
$Y = Bitmask::create(5);
echo $Y; // Bitmask(64|61|3) [ 0000 0101 ]
// Return new object
echo $X->and($Y); // Bitmask(64|61|3) [ 0000 0101 ]
echo $X->and($Y); // Bitmask(64|61|3) [ 0000 0111 ]
// Alter the object
echo $X->clearBit(0); // Bitmask(64|62|2) [ 0000 0010 ]
echo $X->setBit(4); // Bitmask(64|59|5) [ 0001 0010 ]
// Check bit (convention starts from 0)
echo $X->checkBit(2) ? "true":"false"; // false
echo $X->checkBit(4) ? "true":"false"; // true
致谢
支持高质量的代码
许可证
MIT 许可证 (MIT)。更多信息请参阅 LICENSE。