ASCII code is a standard that assigns numbers to characters so they can be handled by computers.
Formally, it is called ASCII = American Standard Code for Information Interchange.
1. What is ASCII code
Computers do not internally understand characters themselves, but treat them as numerical values.
Therefore, for example, numbers are assigned to characters as follows.
A → 65
B → 66
a → 97
0 → 48
This "correspondence table between characters and numerical values" is the ASCII code.
2. What is it used for
The purpose of ASCII code is to ensure that the same characters can be handled with the same meaning between different devices and software.
For example, if the sender sends A as 65 and the receiver also interprets 65 as A, characters can be exchanged correctly.
3. ASCII range
ASCII is originally represented by 7 bits, and the available codes are 0 to 127.
There are a total of 128 types.
They can be broadly divided into the following two types.
Control charactersThese are characters used for communication and control, not for screen display.
Example:
0 : NUL
9 : TAB
10 : LF (line feed)
13: CR (Carriage Return)
27: ESC
These are characters that are actually displayed on a screen or paper.
Example:
32: Space
48-57: 0-9
65-90: A-Z
97-122: a-z
4. Frequently used ASCII codes
Representative examples are as follows.
Character Decimal Hexadecimal Space 32 0x20 0 48 0x30 1 49 0x31 A 65 0x41 Z 90 0x5A a 97 0x61 z 122 0x7A @ 64 0x40 LF 10 0x0A CR 13 0x0D
5. Concrete example
When representing the character string ABC in ASCII code,
A = 65
B = 66
C = 67
it becomes the following.
In other words, ABC can be treated as the numerical sequence
65 66 67
.
Represented in hexadecimal, it is
41 42 43
.
6. The relationship between ASCII and character codes
ASCII is the most fundamental standard among all character codes.
However, ASCII can mainly handle the following:
English letters
Numbers
Some symbols
Control characters
Therefore, Japanese 'Kanji', 'Hiragana', and 'Katakana' cannot be represented in ASCII.
To handle Japanese, character codes such as the following are required:
Shift_JIS
EUC-JP
UTF-8
UTF-16
7. Differences between ASCII and Unicode/UTF-8
This is a point that is easily confused.
ASCIIRange of 0 to 127
Alphanumeric characters and basic symbols only
Very simple
A concept of assigning numbers to characters from all over the world
Capable of handling Japanese, Chinese, emojis, etc.
An encoding method for actually storing and transmitting Unicode
Highly compatible with ASCII
The important thing is that characters in the ASCII range are represented by the same values in UTF-8.
Therefore, knowledge of ASCII is still extremely useful for data centered on alphanumeric characters.
8. Situations where you should be aware of ASCII in the field
In IT practice, you should be aware of ASCII in the following situations.
Text file analysis
Log investigation
Communication protocol analysis
Checking for differences in line break codes
Binary data verification
Investigating character corruption in SQL or CSV
Character determination in programs
For example, in programs, A-Z and 0-9 are sometimes compared using ASCII values.
Example:
0-9 = 48-57
A-Z = 65-90
a-z = 97-122
9. Relationship with line break codes
In ASCII, the following are particularly important as newline control characters.
LF = 10
CR = 13
The handling for each OS is as follows.
Linux / Unix : LF
Windows : CR + LF
Old Mac : CR
This difference can sometimes cause issues in shell scripts or CSV files.
10. What is Extended ASCII
While "ASCII is 0-127", in reality, there are implementations in 8-bit environments that use 128-255 which are commonly referred to as Extended ASCII.
However, this is not a unified standard, and the meaning can differ depending on the environment.
Representative examples:
ISO-8859-1
Windows-1252
Therefore, it is safe to understand that ASCII in the strict sense is only 0-127.
11. Summary
ASCII code is,
a basic character code that assigns numerical values to characters
7-bit, 0-127
handles alphanumeric characters, symbols, and control characters
cannot represent Japanese
It serves as the foundation for understanding UTF-8 and Unicode
Understanding it in this way makes it easier to grasp for practical work.