Caret notation

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

Caret notation is a notation for control characters in ASCII encoding. The notation consists of a caret (^) followed by a single character (usually a capital letter); this digraph stands for a control character whose ASCII code is computed by inverting the 7th bit of the character's ASCII code (which amounts to adding or subtracting 64 from it). As a useful mnemonic, this has the effect of rendering a C0 control character with code N, where N is from 1 to 26 (0x01 to 0x1A) as the Nth capital letter of the alphabet, since capital letters are represented by the ASCII code range 65-90 (0x41-0x5A),

For example, the EOT character with a value of 4 (0x04) is represented as ^D because D is ASCII 68 (0x44), and D is the 4th letter of the alphabet. Similarly, the NUL character with an ASCII code of 0 is represented as ^@ (@ has the ASCII code of 64 (0x40)) and the DEL character with the ASCII code of 127 (0x7F) is usually represented as ^?, because the '?' is ASCII 63 (0x3F) and inverting 7th bit sets it to 1, adding 64 to the value.

Many computer systems allow the user to enter a control character by holding down Ctrl and pressing the letter used in the caret notation. This is practical, because many control characters (e.g. EOT) cannot be entered directly from a keyboard. Although there are many ways to represent control characters, this correspondence between notation and typing makes the caret notation suitable for many applications.

Caret notation is used in many programs, particularly Unix terminal drivers and text file viewers such as more and less.

Alternate notations[edit]

Acorn operating systems for the Atom, BBC Micro, Archimedes and later RISC OS machines use the vertical bar character | in place of the caret. e.g. |M (pronounced "control M") is the carriage return character, ASCII 13. || is the vertical bar character code 124, |? is character 127 as above and |! adds 128 to the code of the following character, so |!|? is character code 128+127 = 255.

See also[edit]