Fred07 / BitSwitch

Database bit-mask helper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BitSwitch

Build Status

BitSwitch is a bit-mask structure handler

Information

For example, given a binary string 0101

each bit present a option is on or off.

using the converted value from binary to integer to present the final options state.

As above, 0101 present d,c,b,a options in order.

5 (int) is the value after convert from binary 0101

in this case, 5 means option a and option c is on, option b and option d is off.

Example

with initial value

extends from example above

$bitSwitch = new BitSwitch(0, ['a', 'b', 'c', 'd']);
$bitSwitch->on('a');
$bitSwitch->on('c');
$result = $bitSwitch->getValue();   // $result = 5

About

Database bit-mask helper


Languages

Language:PHP 100.0%