Unary to Integer Converter

Converts a list of unary strings (one per line) back into integers by counting the "1" characters on each line, keeping a leading "-" as a negative sign. A blank line counts as 0. Lines containing any character other than "1" or a leading "-" are rejected. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-27

Overview

Introduction

This tool reverses unary notation back into ordinary base-10 integers: it counts how many "1" characters appear on each line and reports that count, honoring a leading "-" as a sign.

It pairs with the Integer to Unary Converter to let you round-trip values between the two representations.

What Is Unary to Integer Converter?

A converter that reads a list of unary strings, one per line, and outputs the integer each one represents by counting its "1" characters.

Unlike most list-based tools here, a blank line isn't skipped as filler whitespace; it's read as the unary representation of zero.

How Unary to Integer Converter Works

Each line is checked against a pattern allowing only an optional leading "-" followed by zero or more "1" characters.

The tool counts the "1"s on the line to get the magnitude, then applies a negative sign if the line started with "-" and the count is greater than zero.

Any line containing a character other than "1" or a single leading "-" is rejected with an error naming that line.

When To Use Unary to Integer Converter

Use it to check or grade unary strings produced by hand, by a textbook exercise, or by another tool.

It's useful alongside the Integer to Unary Converter when teaching or demonstrating base-1 notation.

Features

Advantages

  • Simple, predictable counting logic that's easy to verify by hand for small inputs.
  • Explicitly validates input, rejecting anything that isn't pure unary rather than guessing.

Limitations

  • Only recognizes "1" as the unary symbol; other tally conventions (like groups of five) aren't supported.
  • Long unary strings are tedious to read and error-prone to type by hand, which is inherent to the notation itself, not a limitation of this tool.

Examples

Positive unary string

Input

1111

Output

4

Negative unary string

Input

-111

Output

-3

Best Practices & Notes

Best Practices

  • Double-check pasted unary strings for stray characters (spaces, other digits) before conversion, since any non-"1" character invalidates the line.

Developer Notes

Each line is tested against `/^-?1*$/` rather than trimmed and counted blindly, so any stray character fails fast with a specific error; the count of matched "1"s becomes the magnitude, and the leading "-" (if present and the count is nonzero) applies the sign.

Unary to Integer Converter Use Cases

  • Verifying unary output produced by the companion Integer to Unary Converter
  • Grading or checking unary notation exercises
  • Decoding tally-style strings back into ordinary numbers

Common Mistakes

  • Pasting in a decimal number instead of a unary string, which fails validation since digits other than "1" aren't allowed.
  • Expecting a blank line to be skipped like in other list tools, when here it deliberately means 0.

Tips

  • Use short test values first (like "111" or "-11") to confirm you understand the counting behavior before converting longer strings.

References

Frequently Asked Questions