Two-out-of-five code

A two-out-of-five code uses ten possible combinations of two ones and three zeroes to encode the decimal digits using five bits.[1] 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.[2] Each bit position is assigned a weight; the bit value is multiplied by this factor and them 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.[3]

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.[4]

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:

Digit Telecommunication
01236
POSTNET
74210
PLANET Code39
bar widths
12470
1 11000 00011 ┃┃┃╻╻ ▮ | | | ▮
2 10100 00101 ┃┃╻┃╻ | ▮ | | ▮
3 10010 00110 ┃┃╻╻┃ ▮ ▮ | | |
4 01010 01001 ┃╻┃┃╻ | | ▮ | ▮
5 00110 01010 ┃╻┃╻┃ ▮ | ▮ | |
6 10001 01100 ┃╻╻┃┃ | ▮ ▮ | |
7 01001 10001 ╻┃┃┃╻ | | | ▮ ▮
8 00101 10010 ╻┃┃╻┃ ▮ | | ▮ |
9 00011 10100 ╻┃╻┃┃ | ▮ | ▮ |
0 01100 11000 ╻╻┃┃┃ | | ▮ ▮ |
A 1––10 IBM 707x
Sign flags
1––01
+ 0––11
Digit 01234
IBM 707x

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

References

  1. ^  This article incorporates public domain material from Federal Standard 1037C. General Services Administration. Archived from the original on 2022-01-22.
  2. ^ Military Handbook: Encoders - Shaft Angle To Digital (PDF). United States Department of Defense. 1991-09-30. MIL-HDBK-231A. Archived (PDF) from the original on 2020-07-25. Retrieved 2020-07-25. (NB. Supersedes MIL-HDBK-231(AS) (1970-07-01).)
  3. ^  This article incorporates public domain material from Federal Standard 1037C. General Services Administration. Archived from the original on 2022-01-22.
  4. ^ "Vintage Telephone Equipment Museum — XBR #5 MTF Relay Equip". SimpleThinking.com. Archived from the original on 2006-03-16.