new Bitfield(size, bufferopt)
A bitfield backed by a node.js Buffer.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
size | number | Number of bits in the bitfield | |
buffer | Buffer | <optional> | User-supplied buffer to use |
- Source
Example
const { bitfield } = require('@yipsec/blossom');
const bits = new bitfield.Bitfield(8);
bits.set(0, true);
bits.get(0); // true
bits.toggle(0);
bits.get(0); // false
Methods
get(index) → {boolean}
Returns the value of the bit at the given index.
Parameters:
Name | Type | Description |
---|---|---|
index | number | Position of the bit to get |
- Source
Returns:
- Type:
- boolean
set(index, value) → {Bitfield}
Set the bit value at the given index.
Parameters:
Name | Type | Description |
---|---|---|
index | number | Position of the bit to set |
value | boolean | Value to set |
- Source
Returns:
- Type:
- Bitfield
toBuffer() → {Buffer}
Returns the underlying buffer.
- Source
Returns:
- Type:
- Buffer
toggle(index) → {Bitfield}
Flips the bit at the given index.
Parameters:
Name | Type | Description |
---|---|---|
index | number | Position of the bit to flip |
- Source
Returns:
- Type:
- Bitfield