Skip to content

Main content

Unary Code Stop Bit Index Tool

Calculate unary code stop bit index from explicit caller-supplied inputs.

Loading tool…

Description

Decode one unary-prefix run and its consumed length.

A fixed-width bit pattern and the number it represents are different concepts. Unsigned, two's-complement, one's-complement, sign-magnitude and biased encodings use different sign and zero conventions, so a bit-preserving transformation need not preserve numerical meaning.

Decode one unary-prefix run and its consumed length.

When to use this tool

Use Unary Code Stop Bit Index when checking the stated fixed-width representation or encoding convention.

How to use the tool and how it works

  1. Enter bits. Use the units and conventions below.
  2. Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
  3. Read count, consumed. Use the output convention below.

Decode one unary-prefix run and its consumed length. Require binary text beginning with zero or a run of ones followed by zero; count is index of first zero, consumed = count+1.1

Input fieldMeaning and unitsAccepted input
bitsBitsRequired. Text; maximum UTF-16 length 8192.
Output fieldInterpretationReturned shape
countCountRequired. Safe integer.
consumedConsumedRequired. Safe integer.
json
{
  "input": {
    "bits": "111001"
  },
  "output": {
    "count": 3,
    "consumed": 4
  }
}

Limitations and assumptions

  • Trailing binary text is allowed and not decoded; this uses ones as payload and zero as terminator, not the opposite unary convention.
  • Inputs must satisfy both the field types and the cross-field conditions above. Invalid input causes an error; a successful false flag or documented placeholder is a different result.

Alternative or Complementary methods

Choose an explicit representation and width, validate the complete encoded value and use the matching signed or unsigned conversion for the intended numerical interpretation.

References

  1. Calculation and input contract: bitwise/unary-code-stop-bit-index — tool.io

Similar or alternative tools