Kit
Functions

getBitArrayEncoder

getBitArrayEncoder<TSize>(size, config?): FixedSizeEncoder<boolean[], TSize>

Returns an encoder that packs an array of booleans into bits.

This encoder converts a list of boolean values into a compact bit representation, storing 8 booleans per byte.

The backward config option determines whether the bits are stored in MSB-first (false) or LSB-first (true).

For more details, see getBitArrayCodec.

Type Parameters

Type ParameterDescription
TSize extends numberThe number of bytes used to store the bit array.

Parameters

ParameterTypeDescription
sizeTSizeThe number of bytes allocated for the bit array (must be sufficient for the expected boolean count).
config?boolean | BitArrayCodecConfigConfiguration options for encoding the bit array.

Returns

FixedSizeEncoder<boolean[], TSize>

A FixedSizeEncoder<boolean[], TSize> for encoding bit arrays.

Example

Encoding a bit array.

const encoder = getBitArrayEncoder(1);
 
encoder.encode([true, false, true, false, false, false, false, false]);
// 0xa0 (0b10100000)

See

getBitArrayCodec

On this page