Recommend this page to a friend! |
Download |
Info | Documentation | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not yet rated by the users | Total: 37 | All time: 10,955 This week: 560 |
Version | License | PHP version | Categories | |||
bitmap-tools-php 1.0 | MIT/X Consortium ... | 7.4 | Algorithms, Data types, PHP 7 |
Description | Author | |
This package can create and manipulate bitmaps using binary numbers. |
Tools for working with bitmaps
composer require smoren/bitmap-tools
composer install
composer test-init
composer test
use Smoren\BitmapTools\Models\Bitmap;
// Create bitmap by int value:
$bm = Bitmap::create(6); // bitmap: 110
// Create bitmap by true bit positions:
$bm = Bitmap::create([1, 2]); // bitmap: 110
// Basic operations:
$bm = Bitmap::create([0, 2]);
var_dump($bm->getValue()); // 5
var_dump($bm->toArray()); // [0, 2]
var_dump($bm->hasBit(0)); // true
var_dump($bm->hasBit(1)); // false
var_dump($bm->hasBit(2)); // true
$bm = Bitmap::create([0, 1, 2]);
var_dump($bm->getValue()); // 7
var_dump($bm->toArray()); // [0, 1, 2]
$bm = Bitmap::create([]);
var_dump($bm->getValue()); // 0
var_dump($bm->toArray()); // []
// Intersections:
$bm = Bitmap::create(7);
var_dump($bm->intersectsWith(Bitmap::create(1))); // true
var_dump($bm->intersectsWith(Bitmap::create([1, 2]))); // true
$bm = Bitmap::create(6);
var_dump($bm->intersectsWith(Bitmap::create(2))); // true
var_dump($bm->intersectsWith(Bitmap::create(0))); // false
// Inclusions:
$bm = Bitmap::create(6);
var_dump($bm->includes(Bitmap::create(2))); // true (in binary numbers: 110 includes 010)
var_dump($bm->includes(Bitmap::create(1))); // false (in binary numbers: 110 not includes 001)
var_dump($bm->includes(Bitmap::create(3))); // false (in binary numbers: 110 not includes 011)
// Additions:
$bm = Bitmap::create(2); // bitmap: 010
$bm = $bm->add(Bitmap::create(1)); // bitmap: 011
$bm = $bm->add(Bitmap::create(6)); // bitmap: 111
// Subtractions:
$bm = Bitmap::create(15); // bitmap: 1111
$bm = $bm->sub(Bitmap::create(6)); // bitmap: 1001
$bm = $bm->sub(Bitmap::create(3)); // bitmap: 1000
Files (13) |
File | Role | Description | ||
---|---|---|---|---|
.github (1 directory) | ||||
src (2 directories) | ||||
tests (3 files, 2 directories) | ||||
.travis.yml | Data | Auxiliary data | ||
codeception.yml | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
README.md | Doc. | Documentation |
Files (13) | / | tests |
File | Role | Description | ||
---|---|---|---|---|
unit (1 file) | ||||
_support (1 file) | ||||
coding_standard.xml | Data | Auxiliary data | ||
unit.suite.yml | Data | Auxiliary data | ||
_bootstrap.php | Aux. | Auxiliary script |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.