Advanced maths

Linear error correcting code distance and weight enumerator calculator

A linear code’s actual distance depends on its generated codewords, not only its number of parity symbols.

Your numbers

Up to eight rows and code length 24.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

A linear code’s actual distance depends on its generated codewords, not only its number of parity symbols. This calculator reduces a generator matrix to an independent row basis, enumerates the bounded code and returns its minimum nonzero Hamming weight and complete weight distribution.

THE FORMULAC={mG:m in F_p^k}; d_min=min_(c≠0) weight(c); W(z)=Σ_c z^weight(c).

A worked example

The binary repetition code generated by row 1,1,1 contains codewords 000 and 111. Its dimension is one, length is three and minimum distance is three. The Hamming weight enumerator is 1+z³. Repeating the same generator row does not create extra codewords.

Good to know

Prime fields 2–97, generator at most eight rows and length 24, no more than 100,000 distinct codewords. Dependent rows are removed. Minimum nonzero weight is undefined for the zero code. No channel model or unimplemented decoder is implied.

The row span defines the code

Every message coefficient vector selects a linear combination of generator rows over the stated prime field. The set of resulting words is the code, independent of which row basis represents it. Duplicate or dependent generator rows therefore do not increase code dimension, and the calculator reduces them before enumerating distinct words.

The number of independent rows is the dimension k, so a code over GF(p) has exactly p to the k distinct words. The code length is the number of columns. Confusing these quantities can produce an incorrect expected word count even when every individual modular row operation is performed correctly.

A binary repetition code has one nonzero word of weight threeGenerator: (1,1,1) over GF(2)Codeword 000Codeword 111Weights 0 and 3; minimum distance 3Weight enumerator: 1 + z³
The binary repetition code generated by row 1,1,1 contains codewords 000 and 111. Its dimension is one, length is three and minimum distance is three. The Hamming weight enumerator is 1+z³. Repeating the same generator row does not create extra codewords.

The Hamming code parity bit count calculator covers the nearby task. Parity-count formula gives redundancy only; this enumerates an entered linear code and its actual distance.

Hamming distance becomes a weight calculation

For a linear code, the minimum distance between two distinct codewords equals the smallest Hamming weight of a nonzero codeword. Hamming weight counts nonzero symbols, not the sum of their integer values. Thus a field symbol represented by ninety-six contributes one nonzero coordinate just as the symbol one does.

The zero-dimensional code contains only the zero word and has no pair of distinct codewords. This page leaves its minimum nonzero weight undefined instead of setting it to zero. That boundary case avoids implying that the zero code has a nonzero-word witness of weight zero, which would contradict the definition.

The enumerator records more than the minimum

The weight enumerator counts words at every weight, and its coefficients must sum to the total number of codewords. Its constant coefficient is one. These simple checks can reveal duplicate enumeration or a rank mistake even when the reported minimum weight happens to match a familiar example.

The repetition-code default has only two words, making every count visible by inspection. Larger checks compare an independent linear-code implementation and enumerate small row spans in a different order. The exponential word cap is explicit; this page does not claim scalable distance computation for arbitrary long codes or provide an unimplemented noise-channel decoder.

Relate code dimension to the generator row space

A linear code consists of all row combinations uG over GF(p). Its dimension is the rank of G over that field, not automatically the number of input rows. Removing dependent rows leaves the same code and avoids counting several messages that produce one codeword. A rank-k code has p^k distinct codewords.

Hamming weight counts nonzero coordinates, not their numerical magnitudes. For a linear code, the distance between two codewords equals the weight of their difference, which is also a codeword. Therefore the minimum distance equals the minimum nonzero weight. This shortcut relies on linearity and should not be applied to an arbitrary unstructured list of words.

Enumerate repetition and parity codes

Over GF(2), generator row 1,1,1 produces 000 and 111. Their weights are zero and three, so the weight enumerator is 1+z³ and the minimum distance is three. Repeating the same generator row does not create four words because its row rank remains one.

For generator rows 1,0,1 and 0,1,1, the four words are 000,101,011,110. The weight enumerator is 1+3z² and minimum distance two. This code detects any single-symbol error, but its guaranteed unique error-correction radius floor((d−1)/2) is zero. Distance two is therefore not a promise of single-error correction.

Interpret the weight enumerator as a code invariant

If Aj counts words of weight j, the displayed table defines W(z)=ΣAjzj. The coefficients sum to p^k and A0=1. These are useful independent checks on enumeration. Two different generator bases for the same row space must produce the same weight enumerator even though their matrix rows differ.

A coordinate permutation preserves weights and distances, while changing an entry can change the code. Multiplying a coordinate by a nonzero field scalar also preserves zero/nonzero status. Equal weight enumerators alone do not prove two codes are equivalent; the table compresses information and does not encode every relationship among codewords.

Separate distance guarantees from a communication system

Minimum distance d guarantees detection of up to d−1 arbitrary symbol errors and unique correction of up to floor((d−1)/2) under an appropriate decoder. The calculator enumerates the code but does not implement a channel, estimate error probabilities or perform a general decoder. Symbols are field elements, so one changed symbol counts once regardless of its numeric difference.

A zero-dimensional code contains only the zero word, so no minimum nonzero weight exists; the output labels it undefined rather than zero. Enumeration is capped at 100,000 distinct words. A larger code needs structural distance bounds or specialized algorithms, and those bounds should not be mislabeled as a completed exact enumeration.

A few questions, answered

Do repeated generator rows enlarge the code?

No. Only the independent row span determines the dimension and distinct words.

Why is distance undefined for the zero code?

It has no nonzero codeword and no pair of distinct codewords for the reported minimum.

Why does duplicating a generator row not double the code size?

It adds no new direction to the row space. Code size is p raised to the row rank, not p raised to the raw row count.

Does minimum distance two correct one arbitrary error?

No. The guaranteed unique correction radius is floor((d−1)/2), which is zero for d=2, although one error can be detected.

Find your calculator

Start typing to explore the library.