PHPackages                             calabrothers/php-ds-bitmask - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. calabrothers/php-ds-bitmask

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

calabrothers/php-ds-bitmask
===========================

PHP Bitmask Support

1.0.0(6y ago)09MITPHPCI failing

Since Jan 19Pushed 6y ago1 watchersCompare

[ Source](https://github.com/calabrothers/php-ds-bitmask)[ Packagist](https://packagist.org/packages/calabrothers/php-ds-bitmask)[ Docs](http://www.calabrothers.com)[ RSS](/packages/calabrothers-php-ds-bitmask/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

PHP Bitmask Support
===================

[](#php-bitmask-support)

[![Build Status](https://camo.githubusercontent.com/508b28d93eee59766c2bcbbed0cd16605db9b1025d2ffc4aee23181ee98f8c0e/68747470733a2f2f7472617669732d63692e6f72672f63616c6162726f74686572732f7068702d64732d6269746d61736b2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/calabrothers/php-ds-bitmask.svg?branch=master) [![Coverage Status](https://camo.githubusercontent.com/0ab1c011f04ae09a49731b64118bdfe01180f99d0e31288d40fa3439bc8f230f/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f63616c6162726f74686572732f7068702d64732d6269746d61736b2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/calabrothers/php-ds-bitmask?branch=master) [![Total Downloads](https://camo.githubusercontent.com/c3c33fb8b8c34d5bfcebf1e655da905a90449addecd8681b68f237815bea6d71/68747470733a2f2f706f7365722e707567782e6f72672f63616c6162726f74686572732f7068702d64732d6269746d61736b2f646f776e6c6f616473)](https://packagist.org/packages/calabrothers/php-ds-bitmask) [![License](https://camo.githubusercontent.com/2888d8789543131f5811dfd7f4c8231b56c3f7585feb7cf29912e8847ed666bc/68747470733a2f2f706f7365722e707567782e6f72672f63616c6162726f74686572732f7068702d64732d6269746d61736b2f6c6963656e7365)](https://packagist.org/packages/calabrothers/php-ds-bitmask) --&gt;

A class to support bitmask operations.

Install
-------

[](#install)

```
composer require calabrothers/php-ds-bitmask

```

Test
----

[](#test)

```
composer install
composer test

```

HowTo
-----

[](#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:

[](#available-functions)

Let us consider the classic three logical operators:

OperatorNotationAND(a,b)

[![AND](https://camo.githubusercontent.com/ffb643214317d5309f13943b07ab1d05e5ec3c978b83b607ecb5d5695bbb0392/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f6769662e6c617465783f61253230253543776564676525323062)](https://camo.githubusercontent.com/ffb643214317d5309f13943b07ab1d05e5ec3c978b83b607ecb5d5695bbb0392/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f6769662e6c617465783f61253230253543776564676525323062)

 OR(a,b)

[![OR](https://camo.githubusercontent.com/849d5fe5887ca673825436200a39a1c2651f02b4028cbc8ab8798b8397d84ca8/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f6769662e6c617465783f6125323025354376656525323062)](https://camo.githubusercontent.com/849d5fe5887ca673825436200a39a1c2651f02b4028cbc8ab8798b8397d84ca8/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f6769662e6c617465783f6125323025354376656525323062)

NOT(a)

[![NOT](https://camo.githubusercontent.com/a48ff4524ad1fde20935e09620df9fc88d6f11b837dde21921d205aed51dadfe/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f6769662e6c617465783f25354362617225323061)](https://camo.githubusercontent.com/a48ff4524ad1fde20935e09620df9fc88d6f11b837dde21921d205aed51dadfe/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f6769662e6c617465783f25354362617225323061)

Then the basic **Bitmask** object will provide the following operators:

PHP CommandBitwise Operation```
$x->setValue($v)

```

[![SetValue](https://camo.githubusercontent.com/6e38ece391b982cc83e3c133f89c357a2fafe8a7374860b45f3495ab72316394/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f6769662e6c617465783f7825323025334425323076)](https://camo.githubusercontent.com/6e38ece391b982cc83e3c133f89c357a2fafe8a7374860b45f3495ab72316394/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f6769662e6c617465783f7825323025334425323076)

```
$x->setBit($b)

```

[![SetBit](https://camo.githubusercontent.com/92345119c8f3bb87e36a3760a41761dd005c4002ba1749721065868f65ba2401/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f6769662e6c617465783f78253230253344253230782532302535437665652532303225354562)](https://camo.githubusercontent.com/92345119c8f3bb87e36a3760a41761dd005c4002ba1749721065868f65ba2401/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f6769662e6c617465783f78253230253344253230782532302535437665652532303225354562)

```
$x->clearBit($b)

```

[![ClearBit](https://camo.githubusercontent.com/da4ad171307638f6cb3f7d92b1e0569794258e0c4d93ad2cbab0527075f99360/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f6769662e6c617465783f782532302533442532307825323025354377656467652532302535436261722537423225354562253744)](https://camo.githubusercontent.com/da4ad171307638f6cb3f7d92b1e0569794258e0c4d93ad2cbab0527075f99360/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f6769662e6c617465783f782532302533442532307825323025354377656467652532302535436261722537423225354562253744)

```
$x->checkBit($b)

```

[![CheckBit](https://camo.githubusercontent.com/339d2f64e1fbd6ee631f37bf8a178cb0e6b579ab3bbbe95adef21bc90be8625e/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f6769662e6c617465783f253238782532302535437765646765253230322535456225323925323025334525323030)](https://camo.githubusercontent.com/339d2f64e1fbd6ee631f37bf8a178cb0e6b579ab3bbbe95adef21bc90be8625e/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f6769662e6c617465783f253238782532302535437765646765253230322535456225323925323025334525323030)

```
$x->setMask($m)

```

[![SetMask](https://camo.githubusercontent.com/993a6e1ccda0ea442d9de4043ca64c19af80600aac316acb1bf736af9e6324c2/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f6769662e6c617465783f78253230253344253230782532302535437665652532306d)](https://camo.githubusercontent.com/993a6e1ccda0ea442d9de4043ca64c19af80600aac316acb1bf736af9e6324c2/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f6769662e6c617465783f78253230253344253230782532302535437665652532306d)

```
$x->clearMask($m)

```

[![ClearMask](https://camo.githubusercontent.com/a2fefb7393fb2ef28b9b3885334a7c2d25af4ee686e9a9899591ff2f53bb10d4/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f6769662e6c617465783f782532302533442532307825323025354377656467652532302535436261722537426d253744)](https://camo.githubusercontent.com/a2fefb7393fb2ef28b9b3885334a7c2d25af4ee686e9a9899591ff2f53bb10d4/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f6769662e6c617465783f782532302533442532307825323025354377656467652532302535436261722537426d253744)

```
$x->checkMask($m)

```

[![CheckMask](https://camo.githubusercontent.com/3dda49038c9679723e4dbc556d47d5a0cf5bdce56721c4173a783daee3ee9352/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f6769662e6c617465783f2532387825323025354377656467652532306d25323925323025334525323030)](https://camo.githubusercontent.com/3dda49038c9679723e4dbc556d47d5a0cf5bdce56721c4173a783daee3ee9352/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f6769662e6c617465783f2532387825323025354377656467652532306d25323925323025334525323030)

```
$x->not()

```

[![NotFcn](https://camo.githubusercontent.com/cd2dbdc566ea4ba2c473d4eae503426a24421c5bdf3662594d96c7055c0b6289/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f6769662e6c617465783f7925323025334425323025354362617225374278253744)](https://camo.githubusercontent.com/cd2dbdc566ea4ba2c473d4eae503426a24421c5bdf3662594d96c7055c0b6289/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f6769662e6c617465783f7925323025334425323025354362617225374278253744)

```
$x->or($y)

```

[![OrFcn](https://camo.githubusercontent.com/3677e67b4c4522f580bd2628ebdb18d54c8582bfc58ab77c441e7fc2fc9f3643/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f6769662e6c617465783f7a2532302533442532307825323025354376656525323079)](https://camo.githubusercontent.com/3677e67b4c4522f580bd2628ebdb18d54c8582bfc58ab77c441e7fc2fc9f3643/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f6769662e6c617465783f7a2532302533442532307825323025354376656525323079)

```
$x->and($y)

```

[![AndFcn](https://camo.githubusercontent.com/8600e1b4f8bffb484f3e5be6cf97d210bbb04b575e40bdcd57e749471a4f0e3e/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f6769662e6c617465783f7a25323025334425323078253230253543776564676525323079)](https://camo.githubusercontent.com/8600e1b4f8bffb484f3e5be6cf97d210bbb04b575e40bdcd57e749471a4f0e3e/68747470733a2f2f6c617465782e636f6465636f67732e636f6d2f6769662e6c617465783f7a25323025334425323078253230253543776564676525323079)

Example
-------

[](#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

[](#credits)

- [Vincenzo Calabrò](www.cybertronics.cloud/vc)

### Support quality code

[](#support-quality-code)

[![Foo](https://camo.githubusercontent.com/648ad6f048733f167bf65e11a4fd759eef14da88db61ad078bbd5ddea5d57133/68747470733a2f2f7777772e70617970616c6f626a656374732e636f6d2f656e5f55532f692f62746e2f62746e5f646f6e6174655f4c472e676966)](https://paypal.me/muawijhe)

### License

[](#license)

The MIT License (MIT). Please see [LICENSE](LICENSE.md) for more information.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2303d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/11202330?v=4)[muawijhe](/maintainers/muawijhe)[@muawijhe](https://github.com/muawijhe)

---

Top Contributors

[![muawijhe](https://avatars.githubusercontent.com/u/11202330?v=4)](https://github.com/muawijhe "muawijhe (1 commits)")

---

Tags

librarydsbitmaskbitwise

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/calabrothers-php-ds-bitmask/health.svg)

```
[![Health](https://phpackages.com/badges/calabrothers-php-ds-bitmask/health.svg)](https://phpackages.com/packages/calabrothers-php-ds-bitmask)
```

###  Alternatives

[league/iso3166

ISO 3166-1 PHP Library

69536.3M116](/packages/league-iso3166)[dekor/php-array-table

PHP Library for printing associative arrays as text table (similar to mysql terminal console)

296.6M2](/packages/dekor-php-array-table)[yaroslavche/bitmask

BitMask, EnumBitMask

3453.7k1](/packages/yaroslavche-bitmask)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
