Download the PHP package calabrothers/php-ds-bitmask without Composer
On this page you can find all versions of the php package calabrothers/php-ds-bitmask. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download calabrothers/php-ds-bitmask
More information about calabrothers/php-ds-bitmask
Files in calabrothers/php-ds-bitmask
Download calabrothers/php-ds-bitmask
More information about calabrothers/php-ds-bitmask
Files in calabrothers/php-ds-bitmask
Vendor calabrothers
Package php-ds-bitmask
Short Description PHP Bitmask Support
License MIT
Homepage http://www.calabrothers.com
Package php-ds-bitmask
Short Description PHP Bitmask Support
License MIT
Homepage http://www.calabrothers.com
Please rate this library. Is it a good library?
Informations about the package php-ds-bitmask
PHP Bitmask Support
A class to support bitmask operations.
Install
composer require calabrothers/php-ds-bitmask
Test
composer install
composer test
HowTo
Building an object is done via constructor or factory function:
$X = new Bitmask(3); // 000...0011
$Y = Bitmask::create(5); // 000...0101
Available functions:
Let us consider the classic three logical operators:
Operator | Notation |
---|---|
AND(a,b) | ![AND](https://latex.codecogs.com/gif.latex?a%20%5Cwedge%20b) |
OR(a,b) | ![OR](https://latex.codecogs.com/gif.latex?a%20%5Cvee%20b) |
NOT(a) | ![NOT](https://latex.codecogs.com/gif.latex?%5Cbar%20a) |
Then the basic Bitmask object will provide the following operators:
PHP Command | Bitwise Operation |
---|---|
$x->setValue($v) | ![SetValue](https://latex.codecogs.com/gif.latex?x%20%3D%20v) |
$x->setBit($b) | ![SetBit](https://latex.codecogs.com/gif.latex?x%20%3D%20x%20%5Cvee%202%5Eb) |
$x->clearBit($b) | ![ClearBit](https://latex.codecogs.com/gif.latex?x%20%3D%20x%20%5Cwedge%20%5Cbar%7B2%5Eb%7D) |
$x->checkBit($b) | ![CheckBit](https://latex.codecogs.com/gif.latex?%28x%20%5Cwedge%202%5Eb%29%20%3E%200) |
$x->setMask($m) | ![SetMask](https://latex.codecogs.com/gif.latex?x%20%3D%20x%20%5Cvee%20m) |
$x->clearMask($m) | ![ClearMask](https://latex.codecogs.com/gif.latex?x%20%3D%20x%20%5Cwedge%20%5Cbar%7Bm%7D) |
$x->checkMask($m) | ![CheckMask](https://latex.codecogs.com/gif.latex?%28x%20%5Cwedge%20m%29%20%3E%200) |
$x->not() | ![NotFcn](https://latex.codecogs.com/gif.latex?y%20%3D%20%5Cbar%7Bx%7D) |
$x->or($y) | ![OrFcn](https://latex.codecogs.com/gif.latex?z%20%3D%20x%20%5Cvee%20y) |
$x->and($y) | ![AndFcn](https://latex.codecogs.com/gif.latex?z%20%3D%20x%20%5Cwedge%20y) |
Example
$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
Credits
- Vincenzo Calabrò
Support quality code
License
The MIT License (MIT). Please see LICENSE for more information.
All versions of php-ds-bitmask with dependencies
PHP Build Version
Package Version
No informations.
The package calabrothers/php-ds-bitmask contains the following files
Loading the files please wait ....