Home / Learn Embedded C / ASCII and Character Encoding

ASCII and Character Encoding

How characters like A, 7 and \n are really just small numbers.

In shortHow 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

Converting a digit character to a numberC: edit and run

This exact pattern shows up in every command parser that reads digits from a UART line.

CharacterASCII (decimal)ASCII (hex)
'0'480x30
'A'650x41
'a'970x61
'\\n' (newline)100x0A

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

Converting a lowercase letter to uppercase by ASCII mathC: edit and run

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?