Character encoding converter
What is a Character Encoding Converter?
Computers store text as bytes, and a character encoding defines which bytes represent which characters. Most problems with garbled text, known as mojibake, happen when bytes written in one encoding are read in another. This converter shows how a string is represented in UTF-8, UTF-16 and Latin-1 so you can see exactly what is stored and where conversions go wrong.
How to use it
- Type or paste text.
- Compare the byte sequences and byte lengths for each encoding.
- Use the output to debug database columns, API payloads or files that display strange characters.
Example
The word café:
- UTF-8:
63 61 66 C3 A9, 5 bytes. é uses two bytes. - UTF-16LE:
63 00 61 00 66 00 E9 00, 8 bytes. - Latin-1 (ISO-8859-1):
63 61 66 E9, 4 bytes.
If the UTF-8 bytes C3 A9 are decoded as Latin-1, they appear as é, which is why you see café on badly configured websites.
Which encoding should I use?
Use UTF-8 everywhere unless a system forces something else. It covers every Unicode character, is ASCII-compatible and is the default for HTML5, JSON and most modern databases. UTF-16 is used internally by JavaScript, Java and Windows. Latin-1 only covers Western European characters.
Debugging checklist
- Declare
<meta charset='utf-8'>in HTML and sendContent-Type: text/html; charset=utf-8. - In MySQL use
utf8mb4, not the old 3-byteutf8, so emoji can be stored. - Check how CSV files are opened; Excel often assumes a legacy encoding unless the file has a UTF-8 BOM.
Frequently Asked Questions
What is mojibake?
Garbled text that appears when bytes are decoded with the wrong character encoding, for example UTF-8 bytes read as Latin-1.
Why does é take two bytes in UTF-8?
UTF-8 uses one byte for ASCII characters and two to four bytes for everything else. é is outside ASCII, so it needs two bytes.
Should I use UTF-8 or UTF-16?
Use UTF-8 for files, web pages, APIs and databases. UTF-16 is mainly an internal format in some languages and operating systems.
Why can't my MySQL table store emoji?
The legacy utf8 charset in MySQL only supports up to 3 bytes per character. Use utf8mb4 instead.