A two-out-of-five code is a
constant-weight code that provides exactly ten possible combinations of two bits, and is thus used for representing the
decimal digit
A numerical digit (often shortened to just digit) is a single symbol used alone (such as "2") or in combinations (such as "25"), to represent numbers in a positional numeral system. The name "digit" comes from the fact that the ten digits (Latin ...
s using five
bit
The bit is the most basic unit of information in computing and digital communications. The name is a portmanteau of binary digit. The bit represents a logical state with one of two possible values. These values are most commonly represented a ...
s.
Each bit is assigned a weight, such that the set bits sum to the desired value, with an exception for zero.
According to
Federal Standard 1037C
Federal Standard 1037C, titled Telecommunications: Glossary of Telecommunication Terms, is a United States Federal Standard issued by the General Services Administration pursuant to the Federal Property and Administrative Services Act of 1949, ...
:
* each decimal
digit
Digit may refer to:
Mathematics and science
* Numerical digit, as used in mathematics or computer science
** Hindu-Arabic numerals, the most common modern representation of numerical digits
* Digit (anatomy), the most distal part of a limb, such ...
is represented by a binary numeral consisting of five bits of which two are of one kind, called ''ones'', and three are of the other kind, called ''zeros'', and
* the usual weights assigned to the bit positions are 0-1-2-3-6. However, in this scheme,
zero
0 (zero) is a number representing an empty quantity. In place-value notation such as the Hindu–Arabic numeral system, 0 also serves as a placeholder numerical digit, which works by multiplying digits to the left of 0 by the radix, usu ...
is encoded as binary ''01100''; strictly speaking the 0-1-2-3-6 previously claimed is just a
mnemonic
A mnemonic ( ) device, or memory device, is any learning technique that aids information retention or retrieval (remembering) in the human memory for better understanding.
Mnemonics make use of elaborative encoding, retrieval cues, and image ...
device.
The weights give a unique encoding for most digits, but allow two encodings for 3: 0+3 or 10010 and 1+2 or 01100. The former is used to encode the digit 3, and the latter 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
The United States Postal Service (USPS), also known as the Post Office, U.S. Mail, or Postal Service, is an Independent agencies of the United States government, independent agency of the executive branch of the Federal government of the Uni ...
POSTNET barcode
A barcode or bar code is a method of representing data in a visual, Machine-readable data, machine-readable form. Initially, barcodes represented data by varying the widths, spacings and sizes of parallel lines. These barcodes, now commonly refe ...
, 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 switch
In electronics and telecommunications, a crossbar switch (cross-point switch, matrix switch) is a collection of switches arranged in a matrix configuration. A crossbar switch has multiple input and output lines that form a crossed pattern of ...
ing 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
A parity bit, or check bit, is a bit added to a string of binary code. Parity bits are a simple form of error detecting code. Parity bits are generally applied to the smallest units of a communication protocol, typically 8-bit octets (bytes) ...
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
Bi-quinary coded decimal is a numeral encoding scheme used in many abacuses and in some early computers, including the Colossus. The term ''bi-quinary'' indicates that the code comprises both a two-state (''bi'') and a five-state (''quin''ary) ...
References
{{Barcodes
Barcodes
Computer arithmetic
Telephony signals