ASCII table reference with hex and extended
ASCII table reference with hex and extended table. some quick notes about printable characters, control-code and etc.
Full table#
Control-code reference#
A few of the control characters in the 0-31 range come up often in everyday programming:
| Code | Abbr | Name | Common use |
|---|---|---|---|
| 0 | NUL | Null | C-string terminator |
| 8 | BS | Backspace | \b in C strings |
| 9 | HT | Horizontal tab | \t |
| 10 | LF | Line feed | \n, the Unix line ending |
| 12 | FF | Form feed | \f (page break in printers) |
| 13 | CR | Carriage return | \r, half of the Windows \r\n line ending |
| 27 | ESC | Escape | First byte of ANSI escape sequences (e.g. \033[31m for red) |
| 127 | DEL | Delete | Sent by the Delete key on most terminals |
Quick patterns worth remembering#
A few relationships in the table that come up constantly in code:
'0'is 48 (0x30), soc - '0'converts an ASCII digit to its numeric value- All letters differ by exactly 0x20 between upper and lower case — this is why
tolower/touppercan be a single bitwise operation - Digits and uppercase letters are contiguous —
c >= '0' && c <= '9',c >= 'A' && c <= 'Z',c >= 'a' && c <= 'z'are single-range checks '\n'is 10,'\r'is 13 — line feed comes before carriage return
Bonus: four-column ASCII#
Another useful way to read ASCII is to split each 7-bit value into two parts: the top two bits choose the column, and the lower five bits choose the row. I first saw this layout in Four-Column ASCII.
This makes the structure of the table much easier to see. Characters that
differ by 0x20 sit on the same row, which is why A and a, B and b,
and the rest of the alphabet line up exactly.
| Low 5 bits | 00xxxxx | 01xxxxx | 10xxxxx | 11xxxxx |
|---|---|---|---|---|
00000 | NUL | SP | @ | ` |
00001 | SOH | ! | A | a |
00010 | STX | " | B | b |
00011 | ETX | # | C | c |
00100 | EOT | $ | D | d |
00101 | ENQ | % | E | e |
00110 | ACK | & | F | f |
00111 | BEL | ’ | G | g |
01000 | BS | ( | H | h |
01001 | HT | ) | I | i |
01010 | LF | * | J | j |
01011 | VT | + | K | k |
01100 | FF | , | L | l |
01101 | CR | - | M | m |
01110 | SO | . | N | n |
01111 | SI | / | O | o |
10000 | DLE | 0 | P | p |
10001 | DC1 | 1 | Q | q |
10010 | DC2 | 2 | R | r |
10011 | DC3 | 3 | S | s |
10100 | DC4 | 4 | T | t |
10101 | NAK | 5 | U | u |
10110 | SYN | 6 | V | v |
10111 | ETB | 7 | W | w |
11000 | CAN | 8 | X | x |
11001 | EM | 9 | Y | y |
11010 | SUB | : | Z | z |
11011 | ESC | ; | [ | { |
11100 | FS | < | \ | | |
11101 | GS | = | ] | } |
11110 | RS | > | ^ | ~ |
11111 | US | ? | _ | DEL |
▸ stay subscribed
Liked this?
Drop your email and you'll get the next post when it's published. No tracking, one-click unsubscribe.