# tets

`software.visionary.wheeler:tets:2026.10.13` · https://codeberg.org/Wheeler/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 <code>Bits6</code> 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 <code>Bits5</code> 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 <code>int</code> 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.** <code>Bits3</code> to <code>Bits7</code> are the widths narrower than a byte, and together they are the sealed <code>Tet</code>. <code>Bits8</code>, <code>Bits16</code>, <code>Bits32</code> and <code>Bits64</code> are the widths of whole octets, and are open to other implementations. Each is in the package of its name, and each is a <code>FixedBits</code>: a <code>software.visionary.wheeler.Bits</code> with a most and a least significant bit. A tet prints as its bits: a <code>Bits3</code> of five is <code>101</code>.

### Places

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

### A number and its bits

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

### Segments

**Role.** <code>Segmented</code> bits are made of smaller bits, as a run of octets is, and <code>segments()</code> 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

```java
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

```text
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

