Kit
Functions

getBaseXResliceEncoder

getBaseXResliceEncoder(alphabet, bits): VariableSizeEncoder<string>

Returns an encoder for base-X encoded strings using bit re-slicing.

This encoder serializes strings by dividing the input into custom-sized bit chunks, mapping them to an alphabet, and encoding the result into a byte array. This approach is commonly used for encoding schemes where the alphabet's length is a power of 2, such as base-16 or base-64.

For more details, see getBaseXResliceCodec.

Parameters

ParameterTypeDescription
alphabetstringThe set of characters defining the base-X encoding.
bitsnumberThe number of bits per encoded chunk, typically log2(alphabet.length).

Returns

VariableSizeEncoder<string>

A VariableSizeEncoder<string> for encoding base-X strings using bit re-slicing.

Example

Encoding a base-X string using bit re-slicing.

const encoder = getBaseXResliceEncoder('elho', 2);
const bytes = encoder.encode('hellolol'); // 0x4aee

See

getBaseXResliceCodec

On this page