PHP code example of smoren / bitmap-tools

1. Go to this page and download the library: Download smoren/bitmap-tools library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

smoren / bitmap-tools example snippets


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->