ASCII Table Reference
Introduction
In string manipulation and array mapping problems, converting characters to their ASCII integer values (and vice-versa) is a highly common pattern.
In Python, use ord(char) to get the integer value, and chr(int) to get the character.
The Critical Offsets to Memorize
You do not need to memorize the entire ASCII table for an interview. You only need to memorize three numbers:
'A'= 65'a'= 97'0'= 48
Common Patterns
1. Finding the index for a character frequency array (0-25)
# For lowercase letters
index = ord(char) - ord('a')
# For uppercase letters
index = ord(char) - ord('A')
2. Converting a digit character to an integer
3. Toggling Case (Advanced Bitwise)
The difference between 'a' (97) and 'A' (65) is exactly 32.
In binary, 32 is 00100000. You can toggle case using bitwise XOR:
The Complete ASCII Reference
| Char | Dec | Hex | Char | Dec | Hex | Char | Dec | Hex | Char | Dec | Hex |
|---|---|---|---|---|---|---|---|---|---|---|---|
| NUL | 0 | 00 | Space | 32 | 20 | @ | 64 | 40 | ` | 96 | 60 |
| SOH | 1 | 01 | ! | 33 | 21 | A | 65 | 41 | a | 97 | 61 |
| STX | 2 | 02 | " | 34 | 22 | B | 66 | 42 | b | 98 | 62 |
| ETX | 3 | 03 | # | 35 | 23 | C | 67 | 43 | c | 99 | 63 |
| EOT | 4 | 04 | $ | 36 | 24 | D | 68 | 44 | d | 100 | 64 |
| ENQ | 5 | 05 | % | 37 | 25 | E | 69 | 45 | e | 101 | 65 |
| ACK | 6 | 06 | & | 38 | 26 | F | 70 | 46 | f | 102 | 66 |
| BEL | 7 | 07 | ' | 39 | 27 | G | 71 | 47 | g | 103 | 67 |
| BS | 8 | 08 | ( | 40 | 28 | H | 72 | 48 | h | 104 | 68 |
| TAB | 9 | 09 | ) | 41 | 29 | I | 73 | 49 | i | 105 | 69 |
| LF | 10 | 0A | * | 42 | 2A | J | 74 | 4A | j | 106 | 6A |
| VT | 11 | 0B | + | 43 | 2B | K | 75 | 4B | k | 107 | 6B |
| FF | 12 | 0C | , | 44 | 2C | L | 76 | 4C | l | 108 | 6C |
| CR | 13 | 0D | - | 45 | 2D | M | 77 | 4D | m | 109 | 6D |
| SO | 14 | 0E | . | 46 | 2E | N | 78 | 4E | n | 110 | 6E |
| SI | 15 | 0F | / | 47 | 2F | O | 79 | 4F | o | 111 | 6F |
| DLE | 16 | 10 | 0 | 48 | 30 | P | 80 | 50 | p | 112 | 70 |
| DC1 | 17 | 11 | 1 | 49 | 31 | Q | 81 | 51 | q | 113 | 71 |
| DC2 | 18 | 12 | 2 | 50 | 32 | R | 82 | 52 | r | 114 | 72 |
| DC3 | 19 | 13 | 3 | 51 | 33 | S | 83 | 53 | s | 115 | 73 |
| DC4 | 20 | 14 | 4 | 52 | 34 | T | 84 | 54 | t | 116 | 74 |
| NAK | 21 | 15 | 5 | 53 | 35 | U | 85 | 55 | u | 117 | 75 |
| SYN | 22 | 16 | 6 | 54 | 36 | V | 86 | 56 | v | 118 | 76 |
| ETB | 23 | 17 | 7 | 55 | 37 | W | 87 | 57 | w | 119 | 77 |
| CAN | 24 | 18 | 8 | 56 | 38 | X | 88 | 58 | x | 120 | 78 |
| EM | 25 | 19 | 9 | 57 | 39 | Y | 89 | 59 | y | 121 | 79 |
| SUB | 26 | 1A | : | 58 | 3A | Z | 90 | 5A | z | 122 | 7A |
| ESC | 27 | 1B | ; | 59 | 3B | [ | 91 | 5B | { | 123 | 7B |
| FS | 28 | 1C | < | 60 | 3C | \ | 92 | 5C | | | 124 | 7C |
| GS | 29 | 1D | = | 61 | 3D | ] | 93 | 5D | } | 125 | 7D |
| RS | 30 | 1E | > | 62 | 3E | ^ | 94 | 5E | ~ | 126 | 7E |
| US | 31 | 1F | ? | 63 | 3F | _ | 95 | 5F | DEL | 127 | 7F |