A small utility which can be used to manipulate specific bits in a sequence of bits.
npm i @mightyplow/flags
number
Sets one or multiple flags on a sequence of bits.
Kind: global function
Param | Type | Default | Description |
---|---|---|---|
flag | number | Array.<number> |
The bits which should be set | |
[sequence] | number |
0 |
The bit sequence to set the flags on |
Example
import { set } from '@mightyplow/flags'
const Option = {
foo: 2 ** 0,
bar: 2 ** 1,
baz: 2 ** 2
}
const base = 0b000;
console.log(set([Option.foo, Option.baz], base).toSting(2)) // "101"
number
Unsets one or multiple flags on a sequence of bits.
Kind: global function
Param | Type | Default | Description |
---|---|---|---|
flag | number | Array.<number> |
The bits which should be unset | |
[sequence] | number |
0 |
The bit sequence to set the flags on |
number
Inverts one or multiple flags on a sequence of bits.
Kind: global function
Param | Type | Default | Description |
---|---|---|---|
flag | number | Array.<number> |
The bits which should be inverted | |
[sequence] | number |
0 |
The bit sequence to set the flags on |
boolean
Check whether one or multiple flags are set. Returns only true when all requested bits are set.
Kind: global function
Param | Type | Default | Description |
---|---|---|---|
flag | number | Array.<number> |
The bits which should be inverted | |
[sequence] | number |
0 |
The bit sequence to set the flags on |