tets

Visionary Software Solutions Wheeler Tets: digits fewer than eight bits wide, made from numbers

Bits of a fixed width, where the width is the type. A Bits6 is exactly six bits: it is made from a number, read back to that number, and asked for a bit only at a place six bits have.

Rationale

Why. A method that takes a Bits5 cannot be handed six bits, so the signatures of a codec state its field widths and the compiler checks them.

Problem. Formats pack values into fields that are not whole bytes: a base64 digit is six bits, a base32 digit five, a hexadecimal digit four. Code that keeps such a field as an int beside its width holds two facts that can disagree: a value too large for the width, a shift by the wrong count, an index one past the end. Each is found when it runs, if at all.

Solution. Each width is its own type, with its own enum of places. A number the width cannot hold is refused when the bits are made, and a place the width lacks is no constant, so asking for it does not compile.

Key Concepts

Widths

Role. Bits3 to Bits7 are the widths narrower than a byte, and together they are the sealed Tet. Bits8, Bits16, Bits32 and Bits64 are the widths of whole octets, and are open to other implementations. Each is in the package of its name, and each is a FixedBits: a software.visionary.wheeler.Bits with a most and a least significant bit. A tet prints as its bits: a Bits3 of five is 101.

Places

Role. A bit is read with at(place). The place is a constant of the width's own enum (TriadIndex, NibbleIndex, QuintetIndex, SextetIndex, SeptetIndex, ByteIndex, ShortIndex, IntIndex or LongIndex), and ZERO is the least significant bit.

A number and its bits

Role. Each package's Order is a software.visionary.bijection.Bijection between numbers and that width: apply makes the bits and inverse() reads the number back. A tet's Order takes a byte and refuses one too large for the width with DemandFailedException. It has two constants: MOST_SIGNIFICANT_FIRST, as a numeral is written, and LEAST_SIGNIFICANT_FIRST, as DEFLATE and GIF pack their fields. An octet width's Order takes a byte, short, int or long, most significant bit first, and refuses none.

Segments

Role. Segmented bits are made of smaller bits, as a run of octets is, and segments() hands those over whole and in order. A reader that works in octets takes them that way, and any other reader walks the bits one at a time.

Usage

Write 44 as six bits and read it back

import software.visionary.wheeler.Bit;
import software.visionary.wheeler.tets.bits6.Bits6;
import software.visionary.wheeler.tets.bits6.Order;

class Digits {
    public static void main(String[] args) {
        final Bits6<Bit> six = Order.MOST_SIGNIFICANT_FIRST.apply((byte) 44);
        final StringBuilder bits = new StringBuilder();
        for (final Bit bit : six) {
            bits.append(bit.bool() ? '1' : '0');
        }
        System.out.println(bits + " is " + Order.MOST_SIGNIFICANT_FIRST.inverse().apply(six));
    }
}

Output

101100 is 44

Dependencies

  • software.visionary.wheeler:bit:2026.10.13 at Compile
  • software.visionary:bijection:2026.10.13 at Compile
  • software.visionary:index:2026.10.13 at Compile
  • software.visionary.spex:trivia:2026.10.13 at Compile
  • software.visionary.contrax:processor:2026.10.13 at Processor
  • software.visionary:spex-closure:2026.10.13 at Testing

Views

Drawn from the release. A link in a view opens its source at the release tag.

architecture.svg
architecture.svg
classes.software.visionary.wheeler.tets.bits16.svg
classes.software.visionary.wheeler.tets.bits16.svg
classes.software.visionary.wheeler.tets.bits3.svg
classes.software.visionary.wheeler.tets.bits3.svg
classes.software.visionary.wheeler.tets.bits32.svg
classes.software.visionary.wheeler.tets.bits32.svg
classes.software.visionary.wheeler.tets.bits4.svg
classes.software.visionary.wheeler.tets.bits4.svg
classes.software.visionary.wheeler.tets.bits5.svg
classes.software.visionary.wheeler.tets.bits5.svg
classes.software.visionary.wheeler.tets.bits6.svg
classes.software.visionary.wheeler.tets.bits6.svg
classes.software.visionary.wheeler.tets.bits64.svg
classes.software.visionary.wheeler.tets.bits64.svg
classes.software.visionary.wheeler.tets.bits7.svg
classes.software.visionary.wheeler.tets.bits7.svg
classes.software.visionary.wheeler.tets.bits8.svg
classes.software.visionary.wheeler.tets.bits8.svg
classes.software.visionary.wheeler.tets.svg
classes.software.visionary.wheeler.tets.svg
packages.svg
packages.svg