C0 and C1 control codes explained

The C0 and C1 control code or control character sets define control codes for use in text by computer systems that use ASCII and derivatives of ASCII. The codes represent additional information about the text, such as the position of a cursor, an instruction to start a new line, or a message that the text has been received.

C0 codes are the range 00HEX–1FHEX and the default C0 set was originally defined in ISO 646 (ASCII). C1 codes are the range 80HEX–9FHEX and the default C1 set was originally defined in ECMA-48 (harmonized later with ISO 6429). The ISO/IEC 2022 system of specifying control and graphic characters allows other C0 and C1 sets to be available for specialized applications, but they are rarely used.

C0 controls

ASCII defined 32 control characters, plus a necessary extra character for the DEL character, 7FHEX or 01111111BIN (needed to punch out all the holes on a paper tape and erase it).

This large number of codes was desirable at the time, as multi-byte controls would require implementation of a state machine in the terminal, which was very difficult with contemporary electronics and mechanical terminals.

Only a few codes have maintained their use: BEL, ESC, and the "Format " (FEn) characters BS, TAB, LF, VT, FF, and CR. Others are unused or have acquired different meanings such as NUL being the C string terminator. Some data transfer protocols such as ANPA-1312, Kermit, and XMODEM do make extensive use of SOH, STX, ETX, EOT, ACK, NAK and SYN for purposes approximating their original definitions; and some file formats use the "Information Separators" (ISn) such as the Unix info format[1] and Python's string method.[2]

The names of some codes were changed in ISO 6429:1992 (or ECMA-48:1991) to be neutral with respect to writing direction. The abbreviations used were not changed, as the standard had already specified that those would remain unchanged when the standard is translated to other languages. In this table both new and old names are shown for the renamed controls (the old name is the one matching the abbreviation).

ASCII control codes, originally defined in ANSI X3.4.[3] ! ! ! ! Abbreviations! ! Name! ! Description
000NULDoes nothing. The code of blank paper tape, and also used for padding to slow transmission.
101TC1, SOHStart of Heading First character of the heading of a message.
202TC2, STXStart of Text Terminates the header and starts the message text.
303TC3, ETXEnds the message text, starts a footer (up to the next TC character).
404TC4, EOTEnds the transmission of one or more messages.[4] May place terminals on standby.
505EnquiryTrigger a response at the receiving end, to see if it is still present.
606TC6, ACKIndication of successful receipt of a message.
707BELBell, AlertCall for attention from an operator.
808FE0, BSBackspaceMove one position leftwards. Next character may overprint or replace the character that was there.
909FE1, HTCharacter Tabulation,
Horizontal Tabulation
Move right to the next tab stop.
100AFE2, LFLine FeedMove down to the same position on the next line (some devices also moved to the left column).
110BFE3, VTLine Tabulation,
Vertical Tabulation
Move down to the next vertical tab stop.
120CFE4, FFForm FeedMove down to the top of the next page.
130DFE5, CRCarriage ReturnMove to column zero while staying on the same line.
140ESO, LS0Shift OutSwitch to an alternative character set.
150FSI, LS1Shift InReturn to regular character set after SO.
1610Data Link EscapeCause a limited number of contiguously following characters to be interpreted in some different way.[5] [6]
1711DC1, XONDevice Control OneTurn on (DC1 and DC2) or off (DC3 and DC4) devices.Teletype[7] used these for the paper tape reader and the paper tape punch. The first use became the de facto standard for software flow control.[8]
1812DC2, TAPEDevice Control Two
1913DC3, XOFFDevice Control Three
2014DC4, TAPEDevice Control Four
2115TC8, NAKNegative response to a sender, such as a detected error.
2216TC9, SYNSynchronous Idle Sent in synchronous transmission systems when no other character is being transmitted.
2317TC10, ETBEnd of a transmission block of data when data are divided into such blocks for transmission purposes.
2418CANIndicates that the data preceding it are in error or are to be disregarded.
2519EM End of mediumIndicates on paper or magnetic tapes that the end of the usable portion of the tape had been reached.
261ASUBSubstituteReplaces a character that was found to be invalid or in error. Should be ignored.
271BESCEscape
Alters the meaning of a limited number of following bytes.
Nowadays this is almost always used to introduce an ANSI escape sequence.
281CIS4, FS File Separator Can be used as delimiters to mark fields of data structures. US is the lowest level, while RS, GS, and FS are of increasing level to divide groups made up of items of the level beneath it. SP (space) could be considered an even lower level.
291DIS3, GSGroup Separator
301EIS2, RSRecord Separator
311FIS1, USUnit Separator
While not technically part of the C0 control character range, the following two characters can be thought of as having some characteristics of control characters.
 3220SPSpaceMove right one character position.
1277FDELDeleteShould be ignored. Used to delete characters on punched tape by punching out all the holes.

C1 controls

In 1973, ECMA-35 and ISO 2022 attempted to define a method so an 8-bit "extended ASCII" code could be converted to a corresponding 7-bit code, and vice versa. In a 7-bit environment, the Shift Out would change the meaning of the 96 bytes through (i.e. all but the C0 control codes), to be the characters that an 8-bit environment would print if it used the same code with the high bit set. This meant that the range through could not be printed in a 7-bit environment, thus it was decided that no alternative character set could use them, and that these codes should be additional control codes, which become known as the C1 control codes. To allow a 7-bit environment to use these new controls, the sequences ESC @ through ESC _ were to be considered equivalent. The later ISO 8859 standards abandoned support for 7-bit codes, but preserved this range of control characters.

The first C1 control code set to be registered for use with ISO 2022 was DIN 31626, a specialised set for bibliographic use which was registered in 1979.

The more common general-use ISO/IEC 6429 set was registered in 1983, although the ECMA-48 specification upon which it was based had been first published in 1976 and JIS X 0211 (formerly JIS C 6323).[9] Symbolic names defined by and early drafts of ISO 10646, but not in ISO/IEC 6429 (and) are also used.

Except for and in EUC-JP text, and in text transcoded from EBCDIC, the 8-bit forms of these codes were almost never used., and are used to control text terminals and terminal emulators, but almost always by using their 7-bit escape code representations. Nowadays if these codes are encountered it is far more likely they are intended to be printing characters from that position of Windows-1252 or Mac OS Roman.

Name
Description[10]
@12880PADPadding CharacterProposed as a "padding" or "high byte" for single-byte characters to make them two bytes long for easier interoperability with multiple byte characters. Extended Unix Code (EUC) occasionally uses this.[11]
A12981HOPHigh Octet PresetProposed to set the high byte of a sequence of multiple byte characters so they only need one byte each, as a simple form of data compression.
B13082BPHBreak Permitted HereFollows a graphic character where a line break is permitted. Roughly equivalent to a soft hyphen or zero-width space except it does not define what is printed at the line break.
C13183NBHNo Break HereFollows the graphic character that is not to be broken. See also word joiner.
D13284INDIndexMove down one line without moving horizontally, to eliminate ambiguity about the meaning of LF.
E13385NELNext LineEquivalent to CR+LF, to match the EBCDIC control character.
F13486SSAStart of Selected AreaUsed by block-oriented terminals. In xterm moves to the lower-left corner of the screen, since certain software assumes this behaviour.[12]
G13587ESAEnd of Selected Area
H13688HTSSet a tab stop at the current position.
I13789HTJRight-justify the text since the last tab against the next tab stop.
J1388AVTSSet a vertical tab stop.
K1398BPLDTo produce subscripts and superscripts in ISO/IEC 6429.
Subscripts use PLD ''text'' PLU while superscripts use PLU ''text'' PLD.
L1408CPLU
M1418DRIMove up one line.
N1428ESS2Next character is from the G2 or G3 sets, respectively.
O1438FSS3
P14490DCSDevice Control StringFollowed by a string of printable characters (0x20 through 0x7E) and format effectors (0x08 through 0x0D), terminated by ST (0x9C). Xterm defined a number of these.[13]
Q14591PU1Private Use 1Reserved for private function agreed on between the sender and the recipient of the data.
R14692PU2Private Use 2
S14793STSSet Transmit State
T14894CCHCancel characterDestructive backspace, to eliminate ambiguity about meaning of .
U14995MWMessage Waiting
V15096SPAStart of Protected AreaUsed by block-oriented terminals.
W15197EPAEnd of Protected Area
X15298SOSStart of StringFollowed by a control string terminated by (0x9C) which (unlike,, or) may contain any character except SOS or ST.
Y15399SGC,[14] SGCI[15] Single Graphic Character IntroducerIntended to allow an arbitrary Unicode character to be printed; it would be followed by that character, most likely encoded in UTF-1.
Z1549ASCISingle Character IntroducerTo be followed by a single printable character (0x20 through 0x7E) or format effector (0x08 through 0x0D), and to print it as ASCII no matter what graphic or control sets were in use.
[||155||9B||CSI||Control Sequence Introducer||Used to introduce control sequences that take parameters. Used for ANSI escape sequences.|- id="ST"|\||156||9C||ST||String Terminator||Terminates a string started by,,, or . |- id="OSC"|]||157||9D||OSC||Operating System Command||rowspan=3|Followed by a string of printable characters (0x20 through 0x7E) and format effectors (0x08 through 0x0D), terminated by ST (0x9C), intended for use to allow in-band signaling of protocol information, but rarely used for that purpose.

Some terminal emulators, including xterm, use OSC sequences for setting the window title and changing the colour palette. They may also support terminating an OSC sequence with instead of ST.[16] Kermit used APC to transmit commands.[17] |- id="PM"|^||158||9E||PM||Privacy Message|- id="APC"|_||159||9F||APC||Application Program Command|}

Other control code sets

The ISO/IEC 2022 (ECMA-35) extension mechanism allowed escape sequences to change the C0 and C1 sets. The standard C0 control character set shown above is chosen with the sequence and the above C1 set chosen with the sequence .

Several official and unofficial alternatives have been defined, but this is pretty much obsolete. Most were forced to retain a good deal of compatibility with the ASCII controls for interoperability. The standard makes ESC,[18] SP and DEL "fixed" coded characters, which are available in their ASCII locations in all encodings that conform to the standard.[19] It also specifies that if a C0 set included transmission control (TCn) codes, they must be encoded at their ASCII locations[20] and could not be put in a C1 set,[21] and any new transmission controls must be in a C1 set.

Other C0 control code sets

  • ANPA-1312, a text markup language used for news transmission, replaces several C0 control characters.
  • IPTC 7901, the newer international version of the above, has its own variations.
  • Videotex has a completely different set.
  • Teletext also defines a set similar to Videotex.
  • T.61/T.51,[22] and others[23] replaced EM and GS with SS2 and SS3 so these functions could be used in a 7-bit environment.
  • Some sets replaced FS with SS2,[24] (same as ANPA-1312).
  • The now-withdrawn JIS C 6225, designated JIS X 0207 in later sources.[25] replaced FS with CEX or "Control Extension"[26] which introduces control sequences for vertical text behaviour, superscripts and subscripts and for transmitting custom character graphics.

Replacement C1 character sets

  • A specialized C1 control code set is registered for bibliographic use (including string collation), such as by MARC-8.[27] [28] [29]
  • Various specialised C1 control code sets are registered for use by Videotex formats.
  • EBCDIC defines up to 29 additional control codes besides those present in ASCII. When translating EBCDIC to Unicode (or to ISO 8859), these codes are mapped to C1 control characters in a manner specified by IBM's Character Data Representation Architecture (CDRA).[30] Although the New Line (NL) does translate to the ISO/IEC 6429 (although it is often swapped with LF, following UNIX line ending convention), the remainder of the control codes do not correspond. For example, the EBCDIC control and the ECMA-48 control are both used to begin a superscript or end a subscript, but are not mapped to one another. Extended-ASCII-mapped EBCDIC can therefore be regarded as having its own C1 set, although it is not registered with the ISO-IR registry for ISO/IEC 2022.

Unicode

See main article: Unicode control characters. Unicode reserves the 65 code points described above for compatibility with the C0 and C1 control codes, giving them the general category (control). These are:

Unicode only specifies semantics for the C0 format controls HT, LF, VT, FF, and CR (note BS is missing); the C0 information separators FS, GS, RS, US (and SP); and the C1 control NEL. The rest of the codes are transparent to Unicode and their meanings are left to higher-level protocols, with ISO/IEC 6429 suggested as a default.[31]

Unicode includes many additional format effector characters besides these, such as marks, embeds, isolates and pops for explicit bidirectional formatting, and the zero-width joiner and non-joiner for controlling ligature use. However these are given the general category (format) rather than .

See also

References

]

Notes and References

  1. Web site: Adding a new node to Info . Info: The online, menu-driven GNU documentation system . Fox . Brian . Brian Fox (computer programmer) . GNU Project.
  2. Web site: Built-in Types § str.splitlines . The Python Standard Library . Python Software Foundation.
  3. ISO/TC 97/SC 2 . ISO/IEC JTC 1/SC 2#History . The set of control characters of the ISO 646 . 1975 . 1.
  4. Web site: end-of-transmission character (EOT) . . 1996 . https://web.archive.org/web/20160309030543/http://www.its.bldrdoc.gov/fs-1037/dir-014/_2015.htm . 2016-03-09 . dead.
  5. Web site: data link escape character (DLE) . . 1996 . https://web.archive.org/web/20160801021749/http://www.its.bldrdoc.gov/fs-1037/dir-010/_1429.htm . 2016-08-01 . dead.
  6. Web site: Supplementary transmission control functions (an extension of the basic mode control procedures for data communication systems) . ECMA-37 . . 1972.
  7. Web site: Robert McConnell . James Haynes . Richard Warren . Understanding ASCII Codes . NADCOMM . December 2002.
  8. Web site: What is the point of Ctrl-S? . Unix and Linux Stack exchange . 14 February 2019.
  9. Web site: JIS X 02xx 符号 . ja.
  10. Book: Control Functions for Coded Character Sets . ECMA-48:1991 . June 1991 . 5th . ECMA/TC 1 . Ecma International . ECMA.
  11. Book: CJKV Information Processing: Chinese, Japanese, Korean, and Vietnamese Computing . O'Reilly . Lunde, Ken . 2008 . 9780596800925 . 244.
  12. Web site: VT100 Widget Resources (§ hpLowerleftBugCompat) . xterm - terminal emulator for X.
  13. Web site: Device-Control functions . XTerm Control Sequences . Moy . Edward . Gildea . Stephen . Dickey . Thomas.
  14. Web site: Name Aliases . Unicode Character Database . Unicode Consortium.
  15. Web site: Ada 9x Project Report: Character Set Issues for Ada 9x . 1989 . Ronald F. . Brender . Carnegie Mellon University.
  16. Web site: Operating System Commands . XTerm Control Sequences . Moy . Edward . Gildea . Stephen . Dickey . Thomas.
  17. Book: Frank da Cruz. Christine Gianone. Using C-Kermit. 1997. Digital Press. 978-1-55558-164-0. 278.
  18. 104 . ISO/TC97/SC2/WG-7 . ISO/IEC JTC 1/SC 2#History . ECMA . Ecma International . Minimum C0 set for ISO 4873 . 1985-08-01.
  19. Book: ECMA-35 . Character Code Structure and Extension Techniques . 6th . ECMA Standard . 1994 . ECMA . Ecma International . 7 . 6.2: Fixed coded characters.
  20. Book: ECMA-35 . Character Code Structure and Extension Techniques . 6th . ECMA Standard . 1994 . ECMA . Ecma International . 11 . 6.4.2: Primary sets of coded control functions.
  21. Book: ECMA-35 . Character Code Structure and Extension Techniques . 6th . ECMA Standard . 1994 . ECMA . Ecma International . 11 . 6.4.3: Supplementary sets of coded control functions.
  22. ITU . ITU . Teletex Primary Set of Control Functions . 1985 . 106.
  23. Úřad pro normalizaci a měřeni . The set of control characters of ISO 646, with EM replaced by SS2 . 1987 . 140.
  24. ISO/TC 97/SC 2 . ISO/IEC JTC 1/SC 2#History . The set of control characters of ISO 646, with IS4 replaced by Single Shift for G2 (SS2) . 1977 . 36.
  25. Web site: Liaison statement to ISO/TC97/SC2/WG8 and ISO/TC97/SC18/WG8 . ISO/TC97/SC2/WG6 N317.rev . ISO/TC97/SC2/WG6 . ISO/IEC JTC 1/SC 2#History . https://web.archive.org/web/20201026055422/http://original-jpeg.org/Document%20archive/wg8/wg8n0604.pdf . 2020-10-26 . dead.
  26. ISO/TC 97/SC 2 . ISO/IEC JTC 1/SC 2#History . The C0 set of Control Characters of Japanese Standard JIS C 6225-1979 . 1982 . 74.
  27. 40 . Additional Control Codes for Bibliographic Use according to German Standard DIN 31626 . 1979-07-15 . DIN . DIN.
  28. 67 . Additional Control Codes for Bibliographic Use according to International Standard ISO 6630 . 1983-06-01 . ISO/TC 46.
  29. 124 . Additional Control Codes for Bibliographic Use according to International Standard ISO 6630 . 1986-02-01 . ISO/TC 46.
  30. Web site: 3.3 Step 2: Byte Conversion . UTF-EBCDIC . Unicode Technical Report #16 . Umamaheswaran . V.S. . . 1999-11-08 . The 64 control characters […], the ASCII DELETE character (U+007F)[…] are mapped respecting EBCDIC conventions, as defined in IBM Character Data Representation Architecture, CDRA, with one exception -- the pairing of EBCDIC Line Feed and New Line control characters are swapped from their CDRA default pairings to ISO/IEC 6429 Line Feed (U+000A) and Next Line (U+0085) control characters.
  31. Book: https://www.unicode.org/versions/Unicode15.0.0/ch23.pdf#page=3 . 23.1: Control Codes . The Unicode Standard . 15.0.0 . 2022 . . 978-1-936213-32-0 . 914–916.