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
- Enter bits. Use the units and conventions below.
- Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
- 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 field | Meaning and units | Accepted input |
|---|---|---|
| bits | Bits | Required. Text; maximum UTF-16 length 8192. |
| Output field | Interpretation | Returned shape |
|---|---|---|
| count | Count | Required. Safe integer. |
| consumed | Consumed | Required. Safe integer. |
{
"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
Similar or alternative tools
- Thermometer Code Transition Validity
Check a low-ones thermometer code and count adjacent bit transitions.
- Packed Decimal Invalid Nibble Mask
Return invalid packed-decimal nibble positions.