Unary to Hex Converter

Counts a run of unary symbols, repeated "1" characters or "|" tally marks with whitespace ignored, and returns that count as an uppercase hexadecimal number, the inverse of the Hex to Unary Converter. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-26

Overview

Introduction

Unary notation represents a number as a run of repeated symbols with no positional value, which makes counting it back into a compact form like hex the natural inverse operation.

This tool strips whitespace, counts the recognized unary symbols in your input, and converts that count straight to hexadecimal.

What Is Unary to Hex Converter?

A counter-and-converter that reads a string of unary symbols ("1" characters or "|" tally marks, in any mix), counts them while ignoring whitespace, and outputs the count as hex.

It's the direct inverse of Hex to Unary Converter: feeding that tool's output back into this one reproduces the original hex value.

How Unary to Hex Converter Works

All whitespace is stripped from the input first, so newlines, spaces, and tabs used purely for visual grouping don't affect the result.

The remaining characters are validated as only "1"s and/or "|"s; if that check passes, the string's length is the count, which is then converted to hex via JavaScript's Number.prototype.toString(16) and uppercased.

When To Use Unary to Hex Converter

Use it to convert unary-encoded output (from this tool's own Hex to Unary Converter, a textbook exercise, or a tally-mark count) back into a compact number.

It's also a quick way to count a run of tally marks without doing the arithmetic by hand.

Features

Advantages

  • Accepts both "1" characters and "|" tally marks, and any mix of the two, for flexible input.
  • Ignores whitespace, so visually grouped symbols (in fives, for example) still count correctly.
  • No cap on this direction, since counting existing symbols is cheap regardless of length.

Limitations

  • Only recognizes "1" and "|" as valid symbols; any other character is rejected rather than silently ignored.
  • Has no concept of a negative count; unary input is always treated as non-negative.

Examples

Counting a run of 1s

Input

11111

Output

5

Five "1" characters count to 5, which is already a valid single hex digit.

Counting tally marks with whitespace grouping

Input

|||| ||||||||||||||||

Output

14

20 total tally marks (4 + 16) convert to hex 14, since 20 = 1×16 + 4.

Best Practices & Notes

Best Practices

  • Group long runs of symbols with spaces or newlines for readability; they're ignored during counting.
  • If you need to verify a round trip, feed this tool's hex output back into Hex to Unary Converter and compare lengths.

Developer Notes

The implementation strips `/\s+/g` first, validates the remainder against `/^[1|]+$/`, then uses the stripped string's `.length` as the count before calling `count.toString(16).toUpperCase()`; an empty stripped string short-circuits to a count of zero rather than failing validation.

Unary to Hex Converter Use Cases

  • Reversing Hex to Unary Converter's output back to a hex value
  • Counting a block of tally marks from a textbook or worksheet
  • Validating unary-encoded input produced by a computability-theory exercise

Common Mistakes

  • Pasting in digits other than "1" (like "2" or "3") expecting them to be treated as multiple units; only "1" and "|" are recognized symbols.
  • Assuming an empty input is an error; it correctly converts to hex "0".

Tips

  • Mixing "1"s and "|"s in the same input is fine, both count equally toward the total.
  • Use Hex to Unary Converter first if you want to generate a fresh unary string to test this tool against.

References

Frequently Asked Questions