PHP Classes

PHP Bitmap Tools: Create and manipulate bitmaps using binary numbers

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 37 All time: 10,955 This week: 560Up
Version License PHP version Categories
bitmap-tools-php 1.0MIT/X Consortium ...7.4Algorithms, Data types, PHP 7
Description 

Author

This package can create and manipulate bitmaps using binary numbers.

It provides a class that can perform several types of bitmap operations.

Currently, it can:

- Create a bitmap using an array with the bits' numbers set to 1

- Get the intersection of two bitmaps

- Check if two bitmaps are equal

- Add the values of two bitmaps

- Subtract the values of two bitmaps

- Check if a given bit is set

- Convert a bitmap to an array

- Etc...

Picture of Smoren  Freelight
  Performance   Level  
Name: Smoren Freelight <contact>
Classes: 38 packages by
Country: Russian Federation Russian Federation
Age: 35
All time rank: 280978 in Russian Federation Russian Federation
Week rank: 49 Up7 in Russian Federation Russian Federation Up
Innovation award
Innovation award
Nominee: 16x

Documentation

bitmap-tools

Packagist PHP Version Support Scrutinizer Code Quality Coverage Status Build and test License: MIT

Tools for working with bitmaps

How to install to your project

composer require smoren/bitmap-tools

Unit testing

composer install
composer test-init
composer test

Usage

Simple usage

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 folder image Files (13)  
File Role Description
Files folder image.github (1 directory)
Files folder imagesrc (2 directories)
Files folder imagetests (3 files, 2 directories)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file codeception.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (13)  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files (13)  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file test_master.yml Data Auxiliary data

  Files folder image Files (13)  /  src  
File Role Description
Files folder imageInterfaces (1 file)
Files folder imageModels (1 file)

  Files folder image Files (13)  /  src  /  Interfaces  
File Role Description
  Plain text file BitmapInterface.php Class Class source

  Files folder image Files (13)  /  src  /  Models  
File Role Description
  Plain text file Bitmap.php Class Class source

  Files folder image Files (13)  /  tests  
File Role Description
Files folder imageunit (1 file)
Files folder image_support (1 file)
  Accessible without login Plain text file coding_standard.xml Data Auxiliary data
  Accessible without login Plain text file unit.suite.yml Data Auxiliary data
  Accessible without login Plain text file _bootstrap.php Aux. Auxiliary script

  Files folder image Files (13)  /  tests  /  unit  
File Role Description
  Plain text file BitmapTest.php Class Class source

  Files folder image Files (13)  /  tests  /  _support  
File Role Description
  Plain text file UnitTester.php Class Class source

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 Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:37
This week:0
All time:10,955
This week:560Up