Skip to content

Constant-weight code

A binary codebook whose equal-length words all contain the same fixed number of 1s, with error behavior depending on the selected words.

Version
v1 · 2026-10-17 · History
Domain-specific #
14102
Domain group
Formal Sciences
Origin domain
Information Theory
Subdomain
Coding Theory → Information Theory
Aliases
Constant weight code

Core Idea

A binary constant-weight code is a selected set of equal-length binary words in which every word has the same number of 1 positions. For words of length n and weight m, there are n choose m eligible patterns, but the codebook C may select all of them or only a subset. That common-weight rule, together with the chosen set of valid words, identifies the code; a barcode or electronic circuit is one way to use it.[1]

A one-coordinate bit flip changes the weight, so a correct weight check can reject it. Exchanging one active and one inactive position preserves weight; whether the result is another valid word depends on membership in C. A weight check alone therefore does not guarantee detection of every corruption, and the abstract codebook does not specify which checks a receiver performs.[1]

How would you explain it like I'm…

Always-Two-Lights Messages

Imagine a row of five light switches, and every secret message is a pattern of switches turned on. In a Constant-weight code, every allowed message has exactly the same number of switches on, like always two. If you see three on, you know something went wrong.

Same-Number-of-Ones Code

Computers send messages as strings of 0s and 1s. A Constant-weight code is a chosen list of messages that are all the same length and all have the same number of 1s. For example, with five spots and exactly two 1s, there are ten possible patterns, and the list can use all of them or just some. If one bit flips by mistake, the count of 1s changes, so the receiver can tell. But if a 1 and a 0 swap places, the count stays the same, so the receiver must also check whether the pattern is on the list.

Fixed Hamming-Weight Codebook

A binary Constant-weight code is a set of chosen binary words, all of length n, each containing exactly m ones. Every chosen word comes from the pool of n-choose-m possible weight-m words, but the codebook can use all of them or just a subset picked for spacing between words or easy encoding. The fixed-weight rule on the chosen words defines it, not any particular barcode or device. A single bit flip always changes the weight, so checking the count of ones catches it. Swapping one 1 with one 0 keeps the weight, so a weight-only check misses it; the swapped word is a mistaken valid message only if it's in the codebook, and a receiver that checks membership can reject it otherwise.

 

A binary Constant-weight code is a set C of length-n binary words in which every codeword has Hamming weight m. Each codeword lies in the space of n-choose-m weight-m words; C may be that entire space or a subset selected for a target minimum distance or convenient encoding. The abstraction is the fixed-weight constraint on the selected words, not a specific barcode or circuit. Distinguishing eligible from selected words matters: the full two-of-five space has ten patterns, and leaving some unused changes which corrupted words are mistaken for valid messages. Any single bit flip changes the weight and exits the weight-m space, so it is always detectable by weight. An exchange of one 1 and one 0 preserves weight and evades a weight-only check; it becomes an undetected error only if the result is in C, and membership checking can reject it otherwise. Fixed weight thus provides one available rejection test, while stronger detection depends on the codebook and the receiver's checks.

Scope of Application

The rule applies when a carrier can be mapped to ordered binary positions and the selected valid words all have one length and weight. Matrix 2 of 5 uses five ordered bar-and-space elements per digit character, with two wide elements. Its quiet zones, start and stop characters, and optional check digit belong to the whole barcode, outside the digit word.[2]

In asynchronous interconnect, selected m-of-n patterns can use asserted rails as 1 positions. The Manchester study analyzes full and incomplete selected rail codebooks and their completion circuits. POSTNET has another digit-level realization with two tall and three short bars per digit.[3][4]

Clarity

Separate eligible patterns from selected codewords. The binomial number n choose m counts every length-n, weight-m word; |C| counts the valid words actually chosen. These quantities coincide only for a complete codebook. Before making an error claim, ask whether a receiver checks weight, checks membership in C, or applies an additional format-level checksum.[1]

“Two of five” can name the formal count or a particular barcode format. The formal type fixes a word boundary, binary mapping, common weight, and selected codebook. It does not fix printing, scanning, framing, or a self-timed rail handshake.[2][3]

Manages Complexity

Three questions let unlike implementations be compared: where does one codeword begin and end, what physical states map to ordered bits, and which eligible words are actually selected? These questions describe both width-coded barcode digits and asserted-rail groups without importing one system's apparatus into the other.[2][3]

After that shared test, inspect use-specific details separately: codebook size and distance for code design, barcode framing and check digits, or rail completion and acknowledgment circuitry. Those details determine practical performance but do not redefine the common-weight codebook.[1][2][3]

Abstract Reasoning

For specified n and m, check that every member of C has weight m, then compare |C| with the ceiling n choose m. When C has at least two words, pairwise Hamming distances help show which corruptions can change one valid word into another. A singleton still meets the fixed-weight rule, although its pairwise minimum distance is undefined under this convention.[1]

For example, 1100 and 1010 are both length-four, weight-two words. A one-for-one exchange can turn one into the other if both are selected. In the restricted codebook {1100, 0011}, the same exchange from 1100 to 1010 leaves the selected set even though weight remains two. The contrast follows from word weight and membership, not from a promise that every receiver checks both.[1]

Knowledge Transfer

The fixed-weight membership test transfers among barcode digit widths, postal bar heights, and asserted-wire groups when each carrier has an explicit binary mapping. A single fixed-length bit flip leaves the eligible weight class, but application behavior also depends on the selected set and receiver checks.[2][4][3]

The codebook is a specialized Set and Membership object: it is a selected collection of distinct words with bivalent membership. Its hard weight equality is an internal Constraint. Encoding and Decoding becomes relevant when a use adds a source-symbol assignment and paired encoder and decoder; that process is not part of a bare codebook.

Example

Matrix 2 of 5 digit character: one decimal digit has five ordered width-coded elements; mapping wide to 1 gives weight two. The chosen digit patterns are the codebook. The barcode's start, stop, quiet zones, and optional check digit surround these digit words and should not be counted as positions in one digit.[2]

Asynchronous m-of-n rail group: the ordered positions are rails, asserted rails map to 1, and valid groups have weight m. Full and incomplete chosen codebooks appear in the Manchester study. A completion detector belongs to the surrounding communication protocol, not to the mathematical codebook's identity.[3]

Relationships to Other Abstractions

Local relationship map for Constant-weight codeParents appear above the current abstraction, mutual partners to the right, and children below. Node labels state whether each abstraction is prime or domain-specific; colors identify relation types.Constant-weight codeDOMAINPrime abstraction: Constraint — includesConstraintPRIMEPrime abstraction: Set and Membership — is a kind ofSet andMembershipPRIME

Current abstraction Constant-weight code Domain-specific

Parents (2) — outgoing typed relations

  • Constant-weight code is a kind of Set and Membership Prime

    A constant-weight codebook is a set of selected binary words with bivalent membership, specialized by equal length and one common Hamming weight.

  • Constant-weight code includes Constraint Prime

    The hard equality wt(x)=m and its eligible word space are an internal, identity-bearing admissibility constituent of a constant-weight codebook.

Hierarchy paths (2) — routes to 2 parentless roots

Neighborhood in Abstraction Space

Constant-weight code sits in a sparse region of the domain-specific corpus (85th percentile for distinctiveness): few abstractions share its structure, so a faithful description tends to retrieve it precisely.

Family — Unclustered & Miscellaneous (3155 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-11-14

Not to Be Confused With

  • Matrix 2 of 5 as a whole symbol: its digit characters instantiate the rule, while framing and an optional check digit add format-specific structure.[2]
  • The full m-of-n set: this is one special case; a proper selected subset can have different size and error behavior.[1][3]
  • Any error-correcting code: correction requires further error-model and decoding claims; its words need not all share one weight.
  • Any delay-insensitive code: inspect its valid words before claiming a common weight, and keep completion behavior at the protocol level.[3]

References

[1] Smith, Derek H., and Roberto Montemanni. “Some constant weight codes from primitive permutation groups”. The Electronic Journal of Combinatorics 19(4), P4 (2012), doi:10.37236/2702. Full paper consulted; §1 defines binary constant-weight codes, Hamming weight and distance, and maximum-size notation. registry ↩a ↩b ↩c ↩d ↩e ↩f ↩g

[2] Seagull Software, LLC. “Matrix 2 of 5”. Barcode Guide. Lines 37-63 identify five ordered elements per digit, two wide, framing, supported digits, and optional check digit. registry ↩a ↩b ↩c ↩d ↩e ↩f ↩g

[3] Bainbridge, W. J., W. B. Toms, D. A. Edwards, and S. B. Furber. “Delay-insensitive, point-to-point interconnect using m-of-n codes”. Proceedings of the Ninth International Symposium on Asynchronous Circuits and Systems (2003), printed pp. 230-238. Full paper consulted; §§2-8 cover self-timed grouping, full and incomplete m-of-n codes, completion detection, and implementation trade-offs. registry ↩a ↩b ↩c ↩d ↩e ↩f ↩g ↩h

[4] United States Postal Service. “Confirm Service, Product Technology, Barcoding”. Postal Bulletin 22083 (2002), lines 203-213. Documents two tall and three short bars per POSTNET digit. registry ↩a ↩b