Skip to content

This simple library provides a set of functions for easier life when dealing with bitmasks.

Notifications You must be signed in to change notification settings

semisedlak/bitmasking

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bitmasking

This simple library provides a set of functions for easier life when dealing with bitmasks.

You can install it using composer:

$ 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.:

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

const BIT_ALL = BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5;

About

This simple library provides a set of functions for easier life when dealing with bitmasks.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages