A very short article on ASCII characters. Fun fact: ASCII was created by the same guy behind COBOL, and the ESC escape key.

ASCII characters are represented by 7 bits, so that’s 2⁷=128 characters. Some of the characters are the familiar printable characters, and some are the less familiar control characters.

Here are the printable characters, notice they are represented by integers 32 through 126.

Here are the control characters as printed by Haskell. (We see escape sequences involving the mnemonics, or abbreviations.)

Here they are in Emacs Lisp. (We see a textual representation of the keyboard presses.)

> (concat (number-sequence 0 31) '(127))
"^@^A^B^C^D^E^F^G^H \n^K\f^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\^]^^^_^?"

Here they are in Python. (We see the hex code representation.)

Notice in particular the integers 7 through 13 map to a contiguous block of escape sequences from the C language.

Especially \t and \n are not at all obscure, these are often found in strings representing TAB and newline respectively.

Note another common use of the term “escape sequence” is referring to typing the ESC key and a sequence of characters to control devices in more ways than made available by the 33 control characters. Note that ESC is represented by the integer 27, and the control character ^[. For example, many know that Ctrl+[ is easier to press than ESC when using the vim text editor.

Also, \a is the code for alert, or bell or beep. Another representation of beep is ^G, which happens to be the sequence for cancel (“keyboard-quit”) in Emacs, interestingly enough.

The numbering of characters is of note. Consider the table below.

^@^A^B^C^D^E^F^G^H^I^J^K^L^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\^]^&^_
   ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? 
 @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ 
 ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~^?

This layout corresponds with the representation in hexadecimal, like that found at https://en.wikipedia.org/wiki/ASCII#Code_chart. For example, to convert a control character to its corresponding (and/or uppercase) printable character, we add hexadecimal 40. To convert upper case to lowercase, we add hexadecimal 20.

In binary, the character 0 is represented as 0110000, and increments nicely. Similarly for the alphabet letters. So overall, the layout of the ASCII characters is not random, and has some nice properties.

For further research, here are some links. Enjoy!