Understanding the ASCII code lookup — concept and principle
ASCII (American Standard Code for Information Interchange) assigns the numbers 0 to 127 to English letters, digits, punctuation and control signals. It is the common core of almost every modern character set, including UTF-8, so knowing an ASCII value helps when reading hex dumps, writing escape sequences, parsing protocols or debugging invisible characters. Enter a decimal code to see the character and its hex, octal and binary forms.
How it is calculated
- Character: codes 32–126 are printable and shown as the character itself. Codes 0–31 and 127 are control codes and shown by their standard abbreviation (NUL, LF, CR, ESC, DEL and so on).
- Hex: the code in base 16 with a 0x prefix, padded to two digits.
- Octal: the code in base 8.
- Binary: the code in base 2, padded to 8 bits. ASCII needs only 7 bits, so the top bit is always 0.
The principle
ASCII was laid out so that simple bit operations do useful work. Upper-case letters start at 65 (0x41) and lower-case at 97 (0x61): they differ only in bit 5 (value 32), so flipping that bit changes case. Digits 0–9 sit at 48–57 (0x30–0x39), so subtracting 48 turns a digit character into its numeric value. Control codes occupy the first 32 positions, which originally let teleprinters recognise commands from the top bits alone. Every conversion is just a change of base: the same number written with 16, 8 or 2 symbols.
Worked example
- Input: decimal 65.
- 65 lies in the printable range 32–126, so the character is A.
- Hex: 65 = 4 × 16 + 1, so 0x41.
- Octal: 65 = 1 × 64 + 0 × 8 + 1, so 101.
- Binary: 65 = 64 + 1, giving 1000001; padded to 8 bits this is 01000001.
How to read the result
Useful landmarks: 0 = NUL (string terminator in C), 9 = HT (tab), 10 = LF (line feed, Unix newline), 13 = CR (carriage return; Windows uses CR LF), 27 = ESC (start of terminal escape sequences), 32 = space, 48 = "0", 65 = "A", 97 = "a", 127 = DEL. If a file shows unexpected 0x0D bytes, it was probably saved with Windows line endings.
Common mistakes
- Confusing the digit character "7" (code 55) with the number 7.
- Calling values 128–255 "extended ASCII": they belong to other code pages (such as ISO 8859-1 or Windows-1252) and are not part of ASCII.
- Reading octal 101 as decimal one hundred and one.
Frequently asked questions
What is the ASCII code for a space?
32 (0x20). The non-breaking space used on web pages is a different character, U+00A0.
How do I convert lower case to upper case with ASCII codes?
Subtract 32 from a code between 97 and 122, for example 97 ("a") − 32 = 65 ("A").
Is ASCII the same as UTF-8?
For codes 0–127 the bytes are identical, which is why ASCII files are also valid UTF-8.
Sources: ANSI X3.4-1986, American National Standard Code for Information Interchange (ASCII) · IETF RFC 20, ASCII format for Network Interchange (V. Cerf, 1969)