BitArray for PHP >= 5.5

1.2.0 2018-05-28 14:48 UTC


Travis Coveralls Scrutinizer PHP versions Latest Stable Version Packagist Latest Unstable Version License

BitArray for PHP.

This project manipulates compact array of bit values stored internally as strings.

The bit arrays may have variable length specified when an object is created using either:

  • a specific size;
  • a traversable collection;
  • a string representation of bits;
  • a json representation of bits;
  • a slice from another bit array;
  • a concatenation from two others bit arrays.

The project provides methods to get and set bits values using PHP natural syntax as well as the iterator facility offered by the PHP foreach language construct. It also provides methods for bitwise logical operations between two bit arrays and, or, xor and the not operation.

This project uses:


Using composer: either

$ composer create-project chdemko/bitarray:1.2.x-dev --dev; cd bitarray

or create a composer.json file containing

    "require": {
        "chdemko/bitarray": "1.2.x-dev"

and run

$ composer install

Create a test.php file containing

require __DIR__ . '/vendor/autoload.php';

use chdemko\BitArray\BitArray;

$bits = BitArray::fromTraversable([true,false,false,true]);
echo $bits . PHP_EOL;

This should print


See the examples folder for more information.



If you are using this project including publication in research activities, you have to cite it using (BibTeX format). You are also pleased to send me an email to