blossom/bitfield~ Bitfield

new Bitfield(size, bufferopt)

A bitfield backed by a node.js Buffer.

Parameters:
NameTypeAttributesDescription
sizenumber

Number of bits in the bitfield

bufferBuffer<optional>

User-supplied buffer to use

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:
NameTypeDescription
indexnumber

Position of the bit to get

Returns:
Type: 
boolean

set(index, value) → {Bitfield}

Set the bit value at the given index.

Parameters:
NameTypeDescription
indexnumber

Position of the bit to set

valueboolean

Value to set

Returns:
Type: 
Bitfield

toBuffer() → {Buffer}

Returns the underlying buffer.

Returns:
Type: 
Buffer

toggle(index) → {Bitfield}

Flips the bit at the given index.

Parameters:
NameTypeDescription
indexnumber

Position of the bit to flip

Returns:
Type: 
Bitfield