bitpack

Bitpack slice over an integral slice.

Bitpack is used to represent unsigned integer slice with fewer number of bits in integer binary representation.

  1. auto bitpack(Slice!(Iterator, N, kind) slice)
  2. auto bitpack(T[] array)
    @optmath
    bitpack
    (
    size_t pack
    T
    )
    (
    T[] array
    )
  3. auto bitpack(T withAsSlice)

Parameters

pack

counts of bits in the integer.

Return Value

Type: auto

A bitpack slice.

Examples

size_t[10] data;
// creates a packed unsigned integer slice with max allowed value equal to `2^^6 - 1 == 63`.
auto packs = data[].bitpack!6;
assert(packs.length == data.length * size_t.sizeof * 8 / 6);
packs[$ - 1] = 24;
assert(packs[$ - 1] == 24);

packs.popFront;
assert(packs[$ - 1] == 24);

Meta