Hawkynt

Unary Coding

Universal integer coding where number n is represented by n-1 ones followed by a zero. Simple but inefficient for large numbers, mainly used in combination with other codes or for very small values.

Properties

Property Value
Category Compression Algorithms
Sub-category Universal
Security status Not classified
Complexity Not specified
Inventor Information Theory (fundamental)
Year 1940
Origin ❓ Unknown
Source algorithms/compression/unary.js

Security

Status: not classified — treat as unverified.

No vulnerabilities are recorded for this implementation.

Documentation

References

Test vectors

4 vectors ship with this algorithm and run in the test suite. Byte values are hexadecimal.

Vector 1 — Small values - optimal for unary

Field Value
input 01020304
expected 04000000b778

Vector 2 — Single small value

Source: Educational test

Field Value
input 05
expected 01000000f8

Vector 3 — Mixed small values

Source: Educational test

Field Value
input 01030201
expected 04000000bb40

Vector 4 — Large repetitive block (1024x 0x61) - regression for symbol-count header overflow

Field Value
roundTripOnly Yes
input 61616161616161616161616161616161 61616161616161616161616161616161 61616161616161616161616161616161 61616161616161616161616161616161 … (1024 bytes; the full value is in the source)
expected (empty)

← All algorithms