# Code

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Code
> Markdown URL: https://mediated.wiki/source/Code.md
> Source: https://en.wikipedia.org/wiki/Code
> Source revision: 1346569149
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

System of rules to convert information into another form or representation

For other uses, see [Code (disambiguation)](/source/Code_(disambiguation)). "Encoding" redirects here. For other uses, see [Encoding (disambiguation)](/source/Encoding_(disambiguation)).

For [technical reasons](https://en.wikipedia.org/wiki/Wikipedia:Naming_conventions_(technical_restrictions)), terms beginning with "Code#" redirect here. For the musical recordings, see [Code#01](/source/Code_01_Bad_Girl) and [Code#02](/source/Code_02_Pretty_Pretty).

This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed. Find sources: "Code" – news · newspapers · books · scholar · JSTOR (March 2010) (Learn how and when to remove this message)

In [communications](/source/Communication) and [information processing](/source/Data_processing), **code** is a system of rules to convert [information](/source/Information)—such as a [letter](/source/Letter_(alphabet)), [word](/source/Word), sound, image, or [gesture](/source/Gesture)—into another form, sometimes [shortened](/source/Data_compression) or [secret](/source/Secrecy), for communication through a [communication channel](/source/Communication_channel) or storage in a [storage medium](/source/Storage_medium). An early example is an invention of [language](/source/Language), which enabled a person, through [speech](/source/Speech), to communicate what they thought, saw, heard, or felt to others. But speech limits the range of communication to the distance a voice can carry and limits the audience to those present when the speech is uttered. The invention of [writing](/source/Writing), which converted spoken language into [visual](/source/Visual_system) [symbols](/source/Symbol), extended the range of communication across space and [time](/source/Time).

The process of **encoding** converts information from a [source](/source/Communication_source) into symbols for communication or storage. **Decoding** is the reverse process, converting code symbols back into a form that the recipient understands, such as English, Spanish, etc.

One reason for coding is to enable communication in places where ordinary [plain language](/source/Plain_language), spoken or written, is difficult or impossible. For example, [semaphore](/source/Semaphore), where the configuration of [flags](/source/Flag_semaphore) held by a signaler or the arms of a [semaphore tower](/source/Semaphore_line) encodes parts of the message, typically individual letters, and numbers. Another person standing a great distance away can interpret the flags and reproduce the words sent.

## Theory

Main article: [Coding theory](/source/Coding_theory)

In [information theory](/source/Information_theory) and [computer science](/source/Computer_science), a code is usually considered as an [algorithm](/source/Algorithm) that uniquely represents [symbols](/source/Symbols) from some source [alphabet](/source/Alphabet_(computer_science)), by *encoded* strings, which may be in some other target alphabet. An extension of the code for representing sequences of symbols over the source alphabet is obtained by concatenating the encoded strings.

Before giving a mathematically precise definition, this is a brief example. The mapping

- C = { a ↦ 0 , b ↦ 01 , c ↦ 011 } {\displaystyle C=\{\,a\mapsto 0,b\mapsto 01,c\mapsto 011\,\}}

is a code, whose source alphabet is the set { a , b , c } {\displaystyle \{a,b,c\}} and whose target alphabet is the set { 0 , 1 } {\displaystyle \{0,1\}} . Using the extension of the code, the encoded string 0011001 can be grouped into codewords as 0 011 0 01, and these in turn can be decoded to the sequence of source symbols *acab*.

Using terms from [formal language theory](/source/Formal_language_theory), the precise mathematical definition of this concept is as follows: let S and T be two finite sets, called the source and target [alphabets](/source/Alphabet_(computer_science)), respectively. A **code** C : S → T ∗ {\displaystyle C:\,S\to T^{*}} is a [total function](/source/Total_function) mapping each symbol from S to a [sequence of symbols](/source/String_(computer_science)) over T. The **extension** C ′ {\displaystyle C'} of C {\displaystyle C} , is a [homomorphism](/source/Homomorphism#Formal_language_theory) of S ∗ {\displaystyle S^{*}} into T ∗ {\displaystyle T^{*}} , which naturally maps each sequence of source symbols to a sequence of target symbols.

### Variable-length codes

Main article: [Variable-length code](/source/Variable-length_code)

In this section, we consider codes that encode each source (clear text) character by a [code word](/source/Code_word_(figure_of_speech)) from some dictionary, and [concatenation](/source/Concatenation) of such code words give us an encoded string. Variable-length codes are especially useful when clear text characters have different probabilities; see also [entropy encoding](/source/Entropy_encoding).

A *prefix code* is a code with the "prefix property": there is no valid code word in the system that is a [prefix](/source/Prefix_(computer_science)) (start) of any other valid code word in the set. [Huffman coding](/source/Huffman_coding) is the most known algorithm for deriving prefix codes. Prefix codes are widely referred to as "Huffman codes" even when the code was not produced by a Huffman algorithm. Other examples of prefix codes are [telephone country codes](/source/Telephone_country_codes), the country and publisher parts of [ISBNs](/source/ISBN), and the Secondary Synchronization Codes used in the [UMTS](/source/UMTS) [WCDMA](/source/W-CDMA) 3G Wireless Standard.

[Kraft's inequality](/source/Kraft's_inequality) characterizes the sets of codeword lengths that are possible in a prefix code. Virtually any uniquely decodable one-to-many code, not necessarily a prefix one, must satisfy Kraft's inequality.

### Error-correcting codes

Main article: [Error detection and correction](/source/Error_detection_and_correction)

See also: [Block code](/source/Block_code)

Codes may also be used to represent data in a way more resistant to errors in transmission or storage. This so-called [error-correcting code](/source/Error_detection_and_correction) works by including carefully crafted redundancy with the stored (or transmitted) data. Examples include [Hamming codes](/source/Hamming_code), [Reed–Solomon](/source/Reed%E2%80%93Solomon), [Reed–Muller](/source/Reed%E2%80%93Muller_code), [Walsh–Hadamard](/source/Walsh%E2%80%93Hadamard_code), [Bose–Chaudhuri–Hochquenghem](/source/BCH_code), [Turbo](/source/Turbo_code), [Golay](/source/Binary_Golay_code), [algebraic geometry codes](/source/Algebraic_geometry_code), [low-density parity-check codes](/source/Low-density_parity-check_code), and [space–time codes](/source/Space%E2%80%93time_code). Error detecting codes can be optimised to detect *burst errors*, or *random errors*.

## Examples

### Codes in communication used for brevity

Main article: [Brevity code](/source/Brevity_code)

A cable code replaces words (e.g. *ship* or *invoice*) with shorter words, allowing the same information to be sent with fewer [characters](/source/Character_(computing)), more quickly, and less expensively.

Codes can be used for brevity. When [telegraph](/source/Telegraphy) messages were the state of the art in rapid long-distance communication, elaborate systems of [commercial codes](/source/Commercial_code_(communications)) that encoded complete phrases into single mouths (commonly five-minute groups) were developed, so that telegraphers became conversant with such "words" as *BYOXO* ("Are you trying to weasel out of our deal?"), *LIOUY* ("Why do you not answer my question?"), *BMULD* ("You're a skunk!"), or *AYYLU* ("Not clearly coded, repeat more clearly."). [Code words](/source/Code_word_(figure_of_speech)) were chosen for various reasons: [length](/source/Length), [pronounceability](/source/Pronounceability), etc. Meanings were chosen to fit perceived needs: commercial negotiations, military terms for military codes, diplomatic terms for diplomatic codes, any and all of the preceding for espionage codes. Codebooks and codebook publishers proliferated, including one run as a front for the American [Black Chamber](/source/Black_Chamber) run by [Herbert Yardley](/source/Herbert_Yardley) between the First and Second World Wars. The purpose of most of these codes was to save on cable costs. The use of data coding for [data compression](/source/Data_compression) predates the computer era; an early example is the telegraph [Morse code](/source/Morse_code) where more-frequently used characters have shorter representations. Techniques such as [Huffman coding](/source/Huffman_coding) are now used by computer-based [algorithms](/source/Algorithm) to compress large data files into a more compact form for storage or transmission.

### Character encoding

Main article: [Character encoding](/source/Character_encoding)

A character encoding describes how [character](/source/Character_(computing))-based data (text) is encoded. Antiquated encoding systems used a fixed number of [bits](/source/Bit), ranging from 4 to 7, but modern systems use one or more 8-[bit](/source/Bit) [bytes](/source/Byte) for each character. [ASCII](/source/ASCII), the dominate system for decades, uses one byte for each character, and therefore, can encode up to 256 different characters. To support [natural languages](/source/Natural_language) with more characters, other systems were invented that use [more than one byte](/source/Wide_character) or a [variable number of bytes](/source/Variable-width_encoding) for each character. A [writing system](/source/Writing_system) with a large character set such as [Chinese, Japanese and Korean](/source/CJK_characters) can be represented with a multibyte encoding. Early multibyte encodings were fixed-length, meaning that each character is represented by the same number of bytes, making them suitable for decoding via a [lookup table](/source/Lookup_table). On the other hand, a variable-width encoding is more complex to decode since it cannot be decoded via a single lookup table and must be processed sequentially, but it supports a more efficient representation of a large character set by using a smaller representation for more commonly used characters. Today, [UTF-8](/source/UTF-8), an encoding of the [Unicode](/source/Unicode) character set, is the most common text encoding used on the [Internet](/source/Internet).

### Genetic code

Main article: [Genetic code](/source/Genetic_code)

[Biological](/source/Biology) organisms contain genetic material that is used to control their function and development. This is [DNA](/source/DNA), which contains units named [genes](/source/Gene) from which [messenger RNA](/source/Messenger_RNA) is derived. This in turn produces [proteins](/source/Protein) through a [genetic code](/source/Genetic_code) in which a series of triplets ([codons](/source/Codon)) of four possible [nucleotides](/source/Nucleotides) can be translated into one of twenty possible [amino acids](/source/Amino_acid). A sequence of codons results in a corresponding sequence of amino acids that form a protein molecule; a type of codon called a [stop codon](/source/Stop_codon) signals the end of the sequence.

### Gödel code

In [mathematics](/source/Mathematics), a [Gödel code](/source/G%C3%B6del_code) is the basis for the proof of [Gödel](/source/G%C3%B6del)'s [incompleteness theorem](/source/Incompleteness_theorem). Here, the idea is to map [mathematical notation](/source/Mathematical_notation) to a [natural number](/source/Natural_number) (using a [Gödel numbering](/source/G%C3%B6del_numbering)).

### Other

There are codes using colors, like [traffic lights](/source/Traffic_lights), the [color code](/source/Electronic_color_code) employed to mark the nominal value of the [electrical resistors](/source/Resistor) or that of the trashcans devoted to specific types of garbage (paper, glass, organic, etc.).

In [marketing](/source/Marketing), [coupon](/source/Coupon) codes can be used for a financial discount or rebate when purchasing a product from a (usual internet) retailer.

In military environments, specific sounds with the [cornet](/source/Cornet) are used for different uses: to mark some moments of the day, to command the infantry on the battlefield, etc.

Communication systems for sensory impairments, such as [sign language](/source/Sign_language) for deaf people and [braille](/source/Braille) for blind people, are based on movement or tactile codes.

[Musical scores](/source/Sheet_music) are the most common way to encode [music](/source/Music).

Specific games have their own code systems to record the matches, e.g. [chess notation](/source/Chess_notation).

### Cryptography

In the [history of cryptography](/source/History_of_cryptography), [codes](/source/Code_(cryptography)) were once common for ensuring the confidentiality of communications, although [ciphers](/source/Cipher) are now used instead.

Secret codes intended to obscure the real messages, ranging from serious (mainly [espionage](/source/Espionage) in military, diplomacy, business, etc.) to trivial (romance, games) can be any kind of imaginative encoding: [flowers](/source/Language_of_flowers), game cards, clothes, fans, hats, melodies, birds, etc., in which the sole requirement is the pre-agreement on the meaning by both the sender and the receiver.

## Other examples

Other examples of encoding include:

- Encoding (in [cognition](/source/Cognition)) - a basic perceptual process of interpreting incoming stimuli; technically speaking, it is a complex, multi-stage process of converting relatively objective sensory input (e.g., light, sound) into a subjectively meaningful experience.[1]

- Text encoding uses a [markup language](/source/Markup_language) to tag the structure and other features of a text to facilitate processing by computers. (See also [Text Encoding Initiative](/source/Text_Encoding_Initiative).)

- [Semantics encoding](/source/Semantics_encoding) of formal language A informal language B is a method of representing all terms (e.g. programs or descriptions) of language A using language B.

- [Data compression](/source/Data_compression) transforms a signal into a code optimized for [transmission](/source/Transmission_(telecommunications)) or [storage](/source/Data_storage_device), generally done with a [codec](/source/Codec).

- [Neural encoding](/source/Neural_encoding) - the way in which information is represented in [neurons](/source/Neuron).

- [Memory encoding](/source/Memory_encoding) - the process of converting sensations into memories.

- [Television encoding](/source/Television_encoding): [NTSC](/source/NTSC), [PAL](/source/PAL) and [SECAM](/source/SECAM)

Other examples of decoding include:

- [Decoding (computer science)](/source/Parsing)

- [Decoding methods](/source/Decoding_methods), methods in communication theory for decoding codewords sent over a noisy channel

- [Digital signal processing](/source/Digital_signal_processing), the study of signals in a digital representation and the processing methods of these signals

- [Digital-to-analog converter](/source/Digital-to-analog_converter), the use of analog circuit for decoding operations

- Word decoding, the use of [phonics](/source/Phonics) to decipher print patterns and translate them into the sounds of language

## Codes in practical use

In everyday usage of the term, "code" refers to an element of a "code system". For example, the "[postal code](/source/Postal_code) of my home" is a [geocode](/source/Geocode) that identifies a geographical entity in a local system (e.g. [ZIP Code system of U.S.](/source/ZIP_Code)). Typical codes are alphanumeric [identifiers](/source/Identifiers).

[Acronyms](/source/Acronym) and abbreviations can be also considered "codes", and in a sense, all [languages](/source/Language) and [writing systems](/source/Writing_system) are codes for human thought.

[International Air Transport Association airport codes](/source/International_Air_Transport_Association_airport_code) are three-letter codes used to designate airports and used for [bag tags](/source/Bag_tag). [Station codes](/source/Station_code) are similarly used on railways but are usually national, so the same code can be used for different stations if they are in different countries.

Occasionally, a code word achieves an independent existence (and meaning) while the original equivalent phrase is forgotten or at least no longer has the precise meaning attributed to the code word. For example, '30' was widely used in [journalism](/source/Journalism) to mean "end of story", and has been used in [other contexts](/source/-30-) to signify "the end".[2] [3]

## See also

Wikimedia Commons has media related to [Codes](https://commons.wikimedia.org/wiki/Category:Codes).

- [ADDML](/source/ADDML)

- [Asemic writing](/source/Asemic_writing)

- [Cipher](/source/Cipher)

- [Code (semiotics)](/source/Code_(semiotics))

- [Cultural code](/source/Cultural_code)

- [Equipment codes](/source/Equipment_codes)

- [Quantum error correction](/source/Quantum_error_correction)

- [Semiotics](/source/Semiotics)

- [Universal language](/source/Universal_language)

## References

1. **[^](#cite_ref-1)** Secret Warfare: Battle of Codes and Ciphers-Bruce Norman (1973) ISBN 10: 0715362232

1. **[^](#cite_ref-2)** Kogan, Hadass ["So Why Not 29"](http://www.ajr.org/Article.asp?id=4408) [Archived](https://web.archive.org/web/20101212101705/http://ajr.org/Article.asp?id=4408) 2010-12-12 at the [Wayback Machine](/source/Wayback_Machine) American Journalism Review. Retrieved 2012-07-03.

1. **[^](#cite_ref-3)** ["Western Union "92 Code" & Wood's "Telegraphic Numerals""](http://www.civilwarsignals.org/pages/tele/wurules1866/92code.html). Signal Corps Association. 1996. [Archived](https://web.archive.org/web/20120509135118/http://www.civilwarsignals.org/pages/tele/wurules1866/92code.html) from the original on 2012-05-09. Retrieved 2012-07-03.

- Chevance, Fabienne (2017). ["Case for the genetic code as a triplet of triplets"](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5422812). *Proceedings of the National Academy of Sciences of the United States of America*. **114** (18): 4745–4750. [Bibcode](/source/Bibcode_(identifier)):[2017PNAS..114.4745C](https://ui.adsabs.harvard.edu/abs/2017PNAS..114.4745C). [doi](/source/Doi_(identifier)):[10.1073/pnas.1614896114](https://doi.org/10.1073%2Fpnas.1614896114). [PMC](/source/PMC_(identifier)) [5422812](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5422812). [PMID](/source/PMID_(identifier)) [28416671](https://pubmed.ncbi.nlm.nih.gov/28416671).

## Further reading

- *Codes and Abbreviations for the Use of the International Telecommunication Services* (2nd ed.). Geneva, Switzerland: International Telecommunication Union. 1963. [OCLC](/source/OCLC_(identifier)) [13677884](https://search.worldcat.org/oclc/13677884).

---
Adapted from the Wikipedia article [Code](https://en.wikipedia.org/wiki/Code) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Code?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
