Home / Learn Embedded C / ASCII and Character Encoding
ASCII and Character Encoding
How characters like A, 7 and \n are really just small numbers.
What's actually going on
In plain terms
ASCII is a table that assigns every common English character, digit and control code (like newline) a number from 0 to 127; a char in C is just that number stored in one byte.
Why we use it
UART, displays and command parsers all move bytes, not "letters" — understanding that 'A' is really 65 is essential for building and debugging serial protocols.
Under the hood
The compiler replaces a character literal like 'A' with its ASCII numeric value at compile time, so 'A' + 1 is 66, which is 'B'.
Real-world use
- UART command parsing
- Keypad input
- Display drivers
Try it
This exact pattern shows up in every command parser that reads digits from a UART line.
| Character | ASCII (decimal) | ASCII (hex) |
|---|---|---|
| '0' | 48 | 0x30 |
| 'A' | 65 | 0x41 |
| 'a' | 97 | 0x61 |
| '\\n' (newline) | 10 | 0x0A |
A handy trick: digit character to number
Since '0'...'9' are consecutive ASCII codes 48...57, c - '0' converts a digit character to its numeric value — used constantly when parsing text commands coming in over UART.
Try it: shifting letter case with ASCII arithmetic
Lowercase and uppercase letters are a fixed ASCII distance apart, so a single subtraction converts case without any lookup table.
Quick quiz
1. What does the expression ('7' - '0') evaluate to in C?
Both are ASCII codes: '7' is 55 and '0' is 48, so the difference is 7.