https://github.com/semisedlak/bitmasking
This simple library provides a set of functions for easier life when dealing with bitmasks.
https://github.com/semisedlak/bitmasking
bitmask bitmasking php
Last synced: about 1 month ago
JSON representation
This simple library provides a set of functions for easier life when dealing with bitmasks.
- Host: GitHub
- URL: https://github.com/semisedlak/bitmasking
- Owner: semisedlak
- Created: 2023-04-02T18:43:05.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-04-02T20:00:08.000Z (over 2 years ago)
- Last Synced: 2025-08-17T20:56:27.332Z (about 2 months ago)
- Topics: bitmask, bitmasking, php
- Language: PHP
- Homepage:
- Size: 3.91 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Bitmasking
==========This simple library provides a set of functions for easier life when dealing with bitmasks.
You can install it using composer:
```shell
$ composer require semisedlak/bitmasking
```## How it works
Create your own bitmask class which extends from `Semisedlak\Bitmasking\Bitmask` class. Define your bitmask constants in this class. Set the `$bitmask` property and your `$maxBits` property (in fact it means how many "settings" will you have).
## Good to know
When defining a bitmask constants use powers of two, e.g.:
```php
const BIT_1 = 1; // 1 << 0
const BIT_2 = 2; // 1 << 1
const BIT_3 = 4; // 1 << 2
const BIT_4 = 8; // 1 << 3
const BIT_5 = 16; // 1 << 4const BIT_ALL = BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5;
```