ASCII Code
7-bit character encoding, printable and control characters.
ASCII is the encoding that maps every keystroke on your keyboard to a 7-bit integer. From the UART inside every microcontroller to the character ROM of a terminal IC, ASCII is the bedrock of human-readable digital communication.
Core Concept
ASCII stands for American Standard Code for Information Interchange. It defines 128 characters using 7-bit codes (0 to 127). The first 32 codes (0–31) and code 127 are non-printable control characters used for terminal and communication control: NUL (0), LF (10), CR (13), ESC (27), DEL (127).
The 16550A UART IC transmits ASCII serially at baud rates from 50 to 115200 bps. It appends an optional parity bit (making 8 bits total) for error detection. The HD44780 LCD controller uses ASCII codes directly to display characters from its internal ROM — writing 0x41 to its data register displays the letter A.
A key arithmetic relationship: lowercase and uppercase letters differ by exactly 32 (bit 5 differs). So toggling bit 5 of any letter ASCII code switches its case. Digit '0' starts at 48 (0x30), so converting a digit character to its numeric value requires subtracting 48.
Boolean Expression
There is no single Boolean expression for ASCII — it is a lookup table. But the case-toggle rule gives: lowercase_code = uppercase_code OR 0x20; uppercase_code = lowercase_code AND 0xDF. For digit extraction: numeric_value = ASCII_code AND 0x0F (works for digits 0–9 only because their lower nibble matches the digit value).
Given:
Character = 'M'
ASCII of 'M' = 77 decimal = 0100 1101 binary
Formula / Rule:
Lowercase = ASCII OR 0x20 (set bit 5)
Uppercase = ASCII AND 0xDF (clear bit 5)
Step by step:
'M' in binary: 0100 1101
0x20 in binary: 0010 0000
OR result: 0110 1101 = 109 decimal = 'm'
Verification:
'm' = 109, 'M' = 77, difference = 32 = 0x20 -- correct
Digit extraction:
'7' = 55 = 0011 0111
AND 0x0F: 0000 0111 = 7 -- numeric value extracted
Final Answer:
'M' (77) → lowercase 'm' (109) by OR with 0x20
ASCII digit '7' (55) → numeric 7 by AND with 0x0FExam Tip: GATE frequently asks for the ASCII code of a specific character or asks you to identify a character from its code. Memorize three anchor points: '0' = 48 (0x30), 'A' = 65 (0x41), 'a' = 97 (0x61). From these three, you can derive any digit or letter by adding the offset. A common trap: students write ASCII of '5' as 5 instead of 53. Always add 48 to a digit to get its ASCII value.
Key Properties
- 7-bit standard: 128 characters total; extended ASCII uses 8 bits for 256 characters.
- Control characters: 0–31 and 127; printable characters: 32–126.
- 16550A UART: transmits ASCII at up to 115200 bps, 5 V TTL or 3.3 V supply.
- HD44780 LCD controller maps ASCII 0x20–0x7F directly to its character ROM.
- Case toggle: uppercase XOR 0x20 = lowercase (bit 5 flip).
- Digit to value: ASCII_digit - 48 or ASCII_digit AND 0x0F.
- Unicode is backward-compatible with ASCII for the first 128 code points (U+0000 to U+007F).
Quick Revision
- ASCII: 7-bit, 128 characters, standard for text in all digital systems.
- Anchors: NUL=0, SPACE=32, '0'=48, 'A'=65, 'a'=97.
- Case difference = 32 = 0x20 = bit 5.
- Control characters 0–31 and 127 are non-printable.
- UART (16550A) transmits ASCII serially with optional parity bit.
- Extended ASCII: 8-bit, 256 characters, not standardized (varies by code page).
- Unicode UTF-8 encodes ASCII identically — first 128 code points are single byte.
- Exam trap: ASCII of digit 'n' is not n — it is n + 48. Writing ASCII('3') = 3 is a classic wrong answer.
ASCII Code Quiz
Test your knowledge of 7-bit ASCII encoding, character ranges, and control codes.
Q1.The ASCII code for the character 'A' is 65 (decimal). What is the ASCII code for the character 'a'?
Related Articles
BCD Code
Binary coded decimal, valid and invalid BCD, BCD addition.
12 min read
Hamming Code
Error correction, redundant bits, syndrome calculation.
8 min read
Gray Code
Reflected binary code, binary to Gray conversion.
4 min read
Number System Conversions
Direct methods between binary, octal, decimal, hex.
8 min read
Hexadecimal Number System
Base-16, hex to binary and decimal conversion.
9 min read