I have organized the character codes for Japanese and English.
When studying information processing, you may encounter issues related to character codes.
For example, questions about which character codes can be omitted in an XML declaration, or the differences between Shift-JIS, EUC-JP, ISO-2022-JP, UTF-8, and UTF-16.
In daily work, you might not often be strongly conscious of character codes.
However, character codes are extremely important.
This is because without an understanding of character codes, it becomes difficult to identify the cause in situations like the following.
Character corruption occurs when opening a CSV file
Files output from old business systems cannot be read correctly
Japanese text is garbled in a Web API
Japanese text in the body of an email is garbled
Errors occur when loading XML or JSON
Some characters are lost during data migration
Character handling differs between Windows and Linux environments
This time, I will organize information about character codes so that even beginners can understand them.
What is a character code?
A character code is a rule for handling characters in a computer.
Even characters that look like "あ", "A", "1", or "" to humans are treated as numerical values inside a computer.
For example, the characters humans see are things like the following.
A
B
A
I
Mountain
River
However, computers do not understand these as they are.
Computers store characters as a sequence of numbers and display those numbers as characters when needed.
At this time,
"Which character is represented by which number"
is determined by the rules of character encoding.
In other words, character encoding is like a correspondence table between characters and numbers.
Why does mojibake occur?
Mojibake occurs when the interpretation of the character encoding is misaligned.
For example, suppose a file was saved in Shift-JIS.
However, suppose the application opening that file reads it as UTF-8.
Then, it cannot correctly interpret the meaning of the saved byte sequence.
As a result, characters that should have been displayed as Japanese are displayed as a meaningless string of characters.
This is mojibake.
What is important is that mojibake does not necessarily mean that the characters themselves are broken.
In many cases, the problem is a discrepancy like the following:
Character encoding at the time of saving
Character encoding during reading
Character encoding during transmission
Character encoding during reception
Character encoding stored in the database
Character encoding displayed on the screen
If these do not match, character corruption is likely to occur.
Typical character encodings for Japanese
In Japanese, multiple character encodings have been used in the past.
Compared to English, Japanese has a large number of characters, and it is necessary to handle hiragana, katakana, kanji, symbols, and so on.
Therefore, differences in character encoding are prone to becoming an issue in Japanese environments.
I will organize the representative ones.
Shift-JIS
Shift-JIS is a character encoding that has been used for a long time in Japanese Windows environments.
Its characteristics are as follows:
Frequently used in Japanese Windows
Often seen in old business systems and CSV files
1-byte characters and 2-byte characters coexist
Often appears in practical work due to its relationship with CSVs handled in Excel
In Windows environments, it sometimes refers to CP932 or Windows-31J rather than strict Shift-JIS
For exam preparation, it is easy to understand if you memorize it as follows.
Shift-JIS
Japanese Windows
Legacy business systems
CSV
Even today, there are situations where you need to be aware of Shift-JIS when integrating with existing systems.
EUC-JP
EUC-JP is a Japanese character encoding that has been commonly used in UNIX-based environments.
Its characteristics are as follows:
Used in older UNIX and Linux-based environments
May appear in old servers and Japanese UNIX environments
Often replaced by UTF-8 nowadays
For exam preparation, it is good to remember it as follows:
EUC-JP
UNIX-based
Old Linux/UNIX environments
While UTF-8 is standard in current Linux environments, EUC-JP may still appear when dealing with legacy systems.
ISO-2022-JP
ISO-2022-JP is a character encoding that has been commonly used for Japanese email.
Its characteristics are as follows:
Used for Japanese email
Can be represented in 7 bits
High compatibility with old email systems
Switch character sets using escape sequences
In older email systems, there were environments that could not safely handle 8-bit data.
Therefore, ISO-2022-JP, which can be represented in 7 bits, has been used for Japanese email.
For exam preparation, it is good to remember it as follows:
ISO-2022-JP
Japanese email
7 bits
Old email environments
UTF-8
UTF-8 is one of the most widely used character encodings today.
Its features are as follows:
One of the methods to represent Unicode
Widely used in Web, JSON, XML, Linux, cloud environments, etc.
Alphanumeric characters are compatible with ASCII
Can handle Japanese, English, and other languages
Often chosen when building new systems today
A major feature of UTF-8 is its compatibility with ASCII for alphanumeric characters.
For example, the English letter A can be handled as the same byte sequence in both ASCII and UTF-8.
Therefore, it is easy to migrate even in English-speaking regions, and UTF-8 is widely used in current Web and systems.
For exam preparation, it is good to remember it as follows.
UTF-8
Current standard
Frequently used on the Web
Unicode-based
Multilingual support
UTF-16
UTF-16 is also one of the methods for representing Unicode.
Its characteristics are as follows:
Represents characters in 16-bit units
Used internally in Windows and in some programming environments
Important in XML alongside UTF-8
Many Japanese characters are represented in 2 bytes
Some characters are represented in 4 bytes
UTF-16 also frequently appears in XML studies.
In XML, UTF-8 and UTF-16 are handled as standards.
For exam preparation, it is good to remember it as follows.
UTF-16
Unicode-based
16-bit units
Important in XML
Sometimes relevant within Windows
Are there character codes for English as well?
Although not as complex as Japanese, there are representative character codes for English as well.
Since English centers on the alphabet, numbers, and basic symbols, it can be represented with fewer characters than Japanese.
For this reason, ASCII has been used as the standard for a long time.
ASCII
ASCII is the most fundamental character code in the English-speaking world.
Its features are as follows:
Represents alphanumeric characters and basic symbols
Handles 128 types of characters using 7 bits
Important as a basic character code for computers
Compatible with UTF-8
The main characters that can be handled by ASCII are as follows:
A-Z
a-z
0-9
Symbols
Control characters such as line breaks
If you are only dealing with English, ASCII can represent a significant range.
ISO-8859-1
ISO-8859-1 is also known as Latin-1.
Its features are as follows:
A character encoding for Western European languages
Can handle accented characters such as those in French and German, in addition to English
Sometimes seen in older web pages and documents
For example, it handles characters such as the following:
é
ä
ñ
ö
ü
English itself does not often use accented characters, but they may be necessary for names of people, places, or loanwords.
Windows-1252
Windows-1252 is a character encoding for Western Europe that has been used in Windows environments.
Its features are as follows:
Frequently used in Windows environments
Similar to ISO-8859-1, but not exactly the same
Differences appear in quotation marks, dashes, the euro symbol, etc.
These can sometimes appear in old English documents or web pages.
For example, the following symbols are involved.
“
”
’
–
—
€
In practice, when handling old English documents, characters derived from Windows-1252 may sometimes be mixed in.
EBCDIC
EBCDIC is a character encoding that has been used in IBM mainframe systems.
Its characteristics are as follows:
Used in IBM large-scale general-purpose machines
Not commonly used on standard PCs or the web
Sometimes appears in older financial or core systems
For exam preparation, it is good to remember it as follows:
EBCDIC
IBM mainframe
Old large-scale general-purpose machine
While you may not be very conscious of it in everyday web development, it is important for understanding the history of core systems.
The difference between Unicode and UTF-8
One of the most confusing topics regarding character encoding is the relationship between Unicode and UTF-8.
To put it simply, Unicode and UTF-8 do not mean the same thing.
Unicode is a system that assigns a common number to characters from all over the world.
On the other hand, UTF-8 and UTF-16 are methods for representing those Unicode characters as a sequence of bytes on a computer.
It is easy to understand if you think of it in the following way:
Unicode
A standard for assigning numbers to charactersUTF-8
A method for representing Unicode characters as a byte sequenceUTF-16
A method for representing Unicode characters in 16-bit units
In other words, Unicode is a 'concept for a list of characters and their numbering,' while UTF-8 and UTF-16 are 'methods for how to store those numbers.'
Understanding this difference makes it much easier to organize discussions about character encoding.
XML and character encoding
In XML, you sometimes write an XML declaration at the beginning of a document.
For example, it looks like this:
<?xml version="1.0" encoding="UTF-8"?>
Within this,
encoding="UTF-8"
is the encoding declaration.
This means,
'This XML document is written in UTF-8'
is what it signifies.
In XML, UTF-8 and UTF-16 are handled as standards.
On the other hand, when using encodings like Shift-JIS, specifying the encoding is important.
For example, if you read an XML file written in Shift-JIS as UTF-8, it may cause mojibake or parsing errors.
When handling XML, you need to pay attention to the following points:
The actual character encoding of the document
The encoding specified in the XML declaration
The settings of the application reading the file
Specifications such as HTTP headers during transmission and reception
If these do not match, you may not be able to read the XML document correctly.
Character encoding pitfalls to watch out for in practice
Character encoding can cause problems in unexpected places in practice as well.
You should be especially careful in the following cases:
Mojibake when opening CSV files in Excel
Sometimes mojibake occurs when opening a CSV file in Excel.
This happens when the character encoding of the CSV file differs from the character encoding expected by Excel.
For example, if an older version of Excel reads a UTF-8 CSV as Shift-JIS, it may result in mojibake.
Older business systems are based on Shift-JIS
Older business systems sometimes output data based on the assumption of Shift-JIS.
On the other hand, modern Web APIs and cloud services are often based on UTF-8.
When integrating such systems, character encoding conversion may be necessary.
ISO-2022-JP may still appear in emails
While UTF-8 emails are increasing, ISO-2022-JP is sometimes still used in older Japanese emails.
When integrating with email systems, it is necessary to verify how character encoding and MIME are handled.
Windows Shift-JIS is strictly speaking sometimes CP932.
What is referred to as "Shift-JIS" in practice often actually refers to the Windows-extended CP932.
This difference can cause issues with certain symbols, user-defined characters, and platform-dependent characters.
Be careful with user-defined and platform-dependent characters.
Older business systems may use user-defined or platform-dependent characters.
For example, special characters may be used in names of people, companies, addresses, or product names.
During system migrations or data integration, it is necessary to verify whether these characters can be converted correctly.
Character encoding can differ between files, databases, and APIs.
In practice, character encoding is involved in multiple places, such as the following:
Input files
Databases
Applications
Web screens
APIs
Emails
Report output
If the interpretation of character encoding is off in even one place, mojibake can occur.
Therefore, in system integration, it is important to confirm which character encoding is used for receiving, saving, and outputting data.
How to memorize for exam preparation
It is easier to understand character encoding for exams if you organize it as follows.
It is best to memorize representative Japanese character encodings as follows.
Shift-JIS
Japanese Windows, legacy business systems, CSVEUC-JP
UNIX-based, legacy Linux/UNIX environmentsISO-2022-JP
Japanese email, 7-bitUTF-8
Current standard, Web, JSON, XML, multilingual supportUTF-16
Unicode-based, 16-bit units, also important in XML
It is best to memorize representative English character encodings as follows.
ASCII
Basic English character encodingISO-8859-1
For Western European languagesWindows-1252
Character encoding for Western European languages in Windows environmentsEBCDIC
IBM mainframe-basedUTF-8
Current standard
Summary
Character encoding may be a technology you don't usually think about much.
However, it is involved in various practical situations such as character corruption, data migration, CSV processing, email, XML, Web APIs, and integration with legacy business systems.
To summarize the content covered here:
Character encoding is a rule for mapping characters to numerical values
Character corruption occurs due to a mismatch in character encoding interpretation between saving and reading
In Japanese, Shift-JIS, EUC-JP, ISO-2022-JP, UTF-8, and UTF-16 are important.
In English, ASCII, ISO-8859-1, Windows-1252, EBCDIC, and UTF-8 are important.
Unicode is a standard for assigning numbers to characters, while UTF-8 and UTF-16 are methods for storing them.
UTF-8 is often used in modern new systems.
When integrating with older systems, knowledge of Shift-JIS, EUC-JP, etc., is also necessary.
Character encoding is a subtle topic, but it is a very important fundamental skill for system integration and data migration.
Especially when connecting old systems with new ones, understanding character encoding is directly linked to avoiding trouble.
Hashtags
#CharacterEncoding
#Mojibake
#UTF8
#UTF16
#Unicode
#ShiftJIS
#EUCJP
#ISO2022JP
#ASCII
#ITFundamentals
#InformationTechnologyExam
#FundamentalInformationTechnologyEngineer
#AppliedInformationTechnologyEngineer
#SystemDevelopment
#DataMigration
#SystemIntegration
#CSV
#XML
#TechBlog