Computer Character Encoding
Computers store only numbers. Letters, punctuation marks, and symbols need a number assigned to each one. Character encoding is the agreed list that links every character to its number. Imagine two friends who share a secret codebook. One friend writes numbers, and the other reads letters by checking the codebook. Both must own the same book, or the message turns into nonsense.
ASCII: The Classic Code
ASCII stands for American Standard Code for Information Interchange. It uses 7 bits per character, which gives 128 slots. These slots cover English letters, digits, punctuation, and control signals such as the line break.
Character Decimal Binary A 65 01000001 B 66 01000010 a 97 01100001 0 48 00110000 Space 32 00100000
Uppercase letters and lowercase letters hold different numbers. Capital A is 65, and small a is 97. The gap of 32 lets programs switch case with simple math.
Spelling a Word in Numbers
Word: H i Decimal: 72 105 Binary: 01001000 01101001
The word "Hi" travels through wires and storage as the two bytes shown above. The receiving computer looks up 72 and 105 in the same table and displays the word.
The Problem With ASCII
ASCII lacks letters for Hindi, Arabic, Chinese, Japanese, and hundreds of other languages. Extended versions used 8 bits for 256 slots. Each country created its own extension, and files from one country displayed broken symbols on computers elsewhere. The garbled text is known as mojibake.
Sender uses table A → File → Receiver uses table B "café" "café" ← wrong table
Unicode: One Code for the World
Unicode assigns a unique number, called a code point, to every character in every major writing system. It holds more than 150,000 characters, including scripts, mathematical symbols, and emoji. Code points appear in a format such as U+0041 for the letter A.
Character Code Point Language / Type A U+0041 English letter é U+00E9 French letter अ U+0905 Hindi letter 中 U+4E2D Chinese character ♥ U+2665 Symbol
UTF-8, UTF-16, and UTF-32
Unicode defines the numbers. UTF formats define how to store those numbers as bytes.
- UTF-8: Uses 1 to 4 bytes per character. English letters take 1 byte, so ASCII text stays unchanged.
- UTF-16: Uses 2 or 4 bytes. Some operating systems and programming platforms use it internally.
- UTF-32: Uses 4 bytes for every character. It wastes space but offers simple indexing.
UTF-8 Byte Usage English letter █ 1 byte Accented letter ██ 2 bytes Hindi letter ███ 3 bytes Emoji ████ 4 bytes
UTF-8 dominates the web. Over 95 percent of websites declare it as their encoding. The format saves space for English text and still covers every language.
Seeing Encoding in Action
A text editor lets you choose an encoding when you save a file. A web page declares its encoding in the head section with a short line of code. A browser reads that line before it displays the text.
Typing a key → Keyboard sends a scan code → OS converts it to a character code → Program stores bytes (UTF-8) → Screen font draws the shape
Practical Tips
- Save text files in UTF-8 whenever possible.
- Confirm both sender and receiver use the same encoding.
- Strange symbols in place of letters signal an encoding mismatch.
- Fonts decide how a character looks, while encoding decides which character it is.
Encoding on Websites and in Programs
A web page declares its encoding with a short line in the head section. Browsers read that line before they show any text. Databases, email programs, and messaging apps follow the same idea and store text in UTF-8 by default. Programming languages treat text as a sequence of characters. The length of a word in characters may differ from its length in bytes. The word "नमस्ते" holds six characters and takes far more bytes than six English letters.
Key Takeaways
- Encoding links each character to a number.
- ASCII covers 128 English-focused characters.
- Unicode covers writing systems from around the world.
- UTF-8 stores Unicode efficiently and leads the web.
