🧠 How computers turn numbers into characters
Computers don’t understand letters, punctuation, or symbols directly. They only understand numbers — sequences of bits.
So to represent text, we use a character encoding, which is simply a mapping:
number → character
ASCII was the first widely adopted version of this idea.
🔤 ASCII: the classic mapping
ASCII assigns numbers 0–127 to characters like:
| Character | ASCII Code |
|---|---|
| ‘A’ | 65 |
| ‘a’ | 97 |
| ‘0’ | 48 |
| ‘!’ | 33 |
So when you type 'A', the computer stores the number 65.
🧩 How C and C++ expose this
In C and C++, a char is really just a small integer type. You can convert between numbers and characters directly:
int main()
{
char mychar {'A'};
return 0;
}
The above program will define a new variable of type char, which is the keyword we use when we work with characters. There are several ways to define with C++ syntax.
char mychar = 'A';
char mychar = 65;
char mychar {65};
These are all valid ways to define the character a in C++.
🌍 But ASCII isn’t the whole story anymore
ASCII only covers English characters. Modern systems use Unicode, usually encoded as UTF‑8, which can represent:
- all languages
- emoji
- symbols
- mathematical characters
UTF‑8 is backward‑compatible with ASCII, but extends far beyond it.
Converting from and to characters
In programming it is sometimes useful to think of characters as numbers. For example when looking to see if a character is uppercase you can simply look to see if the number is between 65 and 90. If you want to check for lowercase you can simply check for 97 to 122, but what if you wanted to convert lowercase to uppercase? Well that is easy because we can simply subtract a number to do that.
int main()
{
char myLowerCaseLetter {97}; //'a'
char myUpperCaseLetter;
myUpperCaseLetter = myLowerCaseLetter - 32; //'A'
return 0;
}
By treating the char as a number we can simply subtract 32 from a lowercase letter and get the corresponding uppercase letter.
This is widely consider a low level concept and in assembly language this is how you actually have to build the functions we see to do this automatically like std::toupper();
Of course we can do the revers of this as well. Simply add 32 to an upper case character to get the lowercase version.
int main()
{
char myUpperCaseLetter {65}; //'A'
char myLowerCaseLetter;
myLowerCaseLetter = myUpperCaseLetter - 32; //'a'
return 0;
}
One last thought on this topic is that programs commonly use this technique to remove case sensitivity to user inputs. What can be done is to check against uppercase only. When a user enters a lowercase value the program will simply convert to uppercase and complete the check. That’s why std::toupper() is a good choice to use because it will only convert the input to uppercase if it is not already uppercase.
🧩 Why this matters
This technique is everywhere:
- command‑line tools
- menu systems
- text parsers
- configuration file readers
- network protocols
- game input systems