ArticleslgStudy

computer science

Two-out-of-five code

Two-out-of-five code is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Two-out-of-five code rather than just read about it. In short: A two-out-of-five code uses ten possible combinations of two ones and three zeroes to encode the decimal digits using five bits. It is used for its error detection and correction properties, and is a constant-weight code because the Hamming distance to "00000" is the same for all strings.

Two-out-of-five code — main illustration
Two-out-of-five code — illustration

Key takeaways

  • Two-out-of-five code belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Two-out-of-five code to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Two-out-of-five code from memory before moving on to harder problems.

Reference excerpt

A two-out-of-five code uses ten possible combinations of two ones and three zeroes to encode the decimal digits using five bits. It is used for its error detection and correction properties, and is a constant-weight code because the Hamming distance to "00000" is the same for all strings. Each bit position is assigned a weight; the bit value is multiplied by this factor and then the products summed to decode the represented number (with an exception for the number zero). In Federal Standard 1037C, the weights 0-1-2-3-6 give a unique encoding for most digits, but allow two encodings for "3". 10010 (0+3) is used to encode the digit 3, and 01100 (1+2) is used to represent the otherwise unrepresentable zero. The IBM 7070, IBM 7072, and IBM 7074 computers used this code to represent each of the ten decimal digits in a machine word, although they numbered the bit positions 0-1-2-3-4, rather than with weights. Each word also had a sign flag, encoded using a two-out-of-three code, that could be A Alphanumeric, − Minus, or + Plus. When copied to a digit, the three bits were placed in bit positions 0-3-4. (Thus producing the numeric values 3, 6 and 9, respectively.) A variant is the United States Postal Service POSTNET barcode, used to represent the ZIP Code for automated mail sorting and routing equipment. This uses two tall bars as ones and three short bars as zeros. Here, the weights assigned to the bit positions are 7-4-2-1-0. Again, zero is encoded specially, using the 7+4 combination (binary 11000) that would naturally encode 11. This method was also used in North American telephone multi-frequency and crossbar switching systems. The USPS Postal Alpha Numeric Encoding Technique (PLANET) uses the same weights, but with the opposite bar-height convention. The Code 39 barcode uses weights 1-2-4-7-0 (i.e. LSB first, Parity bit last) for the widths of its bars, but it also encodes two bits of extra information in the spacing between bars. The || ||| spacing is used for digits. The following table represents decimal digits from 0 to 9 in various two-out-of-five code systems:

The limit on the number of bits set is similar to, but strictly stronger than, a parity check. All constant-weight codes, including the two-out-of-five code, can not only detect any single-bit error, but also detect any unidirectional errors -- any case where all errors in a codeword are of a single type (0→1 or 1→0).

See also Bi-quinary coded decimal

References

Illustrations

Two-out-of-five code: 2 of 5 barcode (non-interleaved)
2 of 5 barcode (non-interleaved)
Two-out-of-five code: POSTNET barcode
POSTNET barcode

Worked examples

Example 1 — a first encounter with Two-out-of-five code

Start with the simplest possible case. Write down what Two-out-of-five code claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Two-out-of-five code before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Two-out-of-five code ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Two-out-of-five code

In research
Two-out-of-five code appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Two-out-of-five code in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Two-out-of-five code is common in secondary-school and first-year university syllabi. It links to neighbouring topics Barcodes, Computer arithmetic, Telephony signals, so understanding it makes those chapters shorter.
In everyday life
Look for Two-out-of-five code outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Two-out-of-five code” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Two-out-of-five code in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Two-out-of-five code means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Two-out-of-five code out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Two-out-of-five code in simple terms?

A two-out-of-five code uses ten possible combinations of two ones and three zeroes to encode the decimal digits using five bits. It is used for its error detection and correction properties, and is a constant-weight code because the Hamming distance to "00000" is the same for all strings.

Why does Two-out-of-five code matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Two-out-of-five code?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Two-out-of-five code.

Tags

  • Barcodes
  • Computer arithmetic
  • Telephony signals

Keep exploring