Introduction
These are 7-bit encodings of Japanese, Korean and Chinese for mail systems that only
carry ASCII. Every byte is below 80. Escape sequences switch between
character sets, so the same two bytes can be two ASCII letters or one Chinese
character, depending on the last switch. ISO-2022-JP is
RFC 1468, ISO-2022-KR
RFC 1557 and ISO-2022-CN
RFC 1922; all three follow the
scheme of ISO/IEC 2022. HZ, RFC 1843, uses ~ sequences instead. As far
as a byte stream goes they are valid ASCII, so without this format they would read
as UTF-8 full of stray letters.
A file dropped on any page of this site opens in the explorer, which decodes them, shows every shift sequence as its own item, and decodes each character it can.
Structure
0Lines of bytes below80, each interpreted through the current shift state, followed by a line endingvaries
Byte order mark
These encodings have no byte order mark. Nothing but the escape sequences says the file is one of them.
Encoding
Each double-byte set writes a character as two bytes from 21 to
7E. The double-byte tables are the same as those of the 8-bit encodings
(EUC-JP, EUC-KR, GB 2312), with the top bit of both bytes cleared.
ISO-2022-JP (RFC 1468)
The text starts in ASCII. An escape sequence selects a character set into G0 until the next one.
| Escape sequence | Bytes | Selects | Width |
|---|---|---|---|
ESC ( B | 1B 28 42 | ASCII | 1 |
ESC ( J | 1B 28 4A | JIS X 0201 Roman (the same as ASCII except \ and ~) | 1 |
ESC ( I | 1B 28 49 | JIS X 0201 Katakana (not part of RFC 1468, but widely used) | 1 |
ESC $ @ | 1B 24 40 | JIS C 6226-1978 (JIS X 0208-1978) | 2 |
ESC $ B | 1B 24 42 | JIS X 0208-1983 | 2 |
ESC $ ( @, ESC $ ( B | 1B 24 28 40, 1B 24 28 42 | the long forms of the two above | 2 |
ESC $ ( D | 1B 24 28 44 | JIS X 0212-1990 (RFC 2237, not in RFC 1468) | 2 |
RFC 1468 says that if a line has JIS X 0208 characters it must switch to ASCII or
JIS X 0201 Roman before the end of the line, “which means that the next line starts
in the character set that was switched to before the end of the previous line”.
The explorer does that: a line starts in the ASCII or Roman set that the line before
it ended in (ASCII at the start of the file), so a line after one that ended in
Roman shows ¥ for 5C and ‾ for 7E. A line that ends
inside a two-byte set breaks the rule: its last character is flagged in the tree,
and the next line starts in ASCII. The double-byte characters decode through the
browser’s EUC-JP decoder.
JIS C 6226-1978 and JIS X 0208-1983. The 1983 revision exchanged
the places of 22 pairs of kanji and replaced the form of others, so
ESC $ @ text differs from ESC $ B text in 82 cells. The
explorer decodes ESC $ B through the browser’s EUC-JP decoder and
ESC $ @ through the same with the 1978 characters in those cells,
from the table of Harjit Singh’s
“JIS 1978, 1983, 1990
…”: the 22 pairs are 16-19 and 82-45, 18-09 and 82-84, 19-34 and 73-58, 19-41
and 57-88, 19-86 and 67-62, 20-35 and 62-85, 20-50 and 75-61, 23-59 and 80-84,
25-60 and 66-72, 28-41 and 73-02, 31-57 and 80-55, 33-08 and 76-45, 36-59 and 52-68,
37-55 and 66-74, 37-78 and 59-77, 37-83 and 62-25, 38-86 and 77-78, 39-72 and
74-04, 41-16 and 59-56, 43-89 and 48-54, 44-89 and 73-14, and 47-22 and 68-38 (row
and cell); and 38 cells had the older form of a kanji: 16-02, 17-75, 18-10, 19-90,
22-02, 22-38, 22-77, 23-50, 24-20, 25-77, 28-40, 29-11, 30-53, 30-63, 32-70, 33-63,
33-73, 34-45, 35-29, 36-47, 37-22, 37-31, 37-88, 38-34, 39-25, 39-77, 40-14, 40-16,
43-43, 43-74, 44-45, 45-58, 45-73, 47-25, 49-59, 54-02, 58-25, 63-70 and 64-86. For
example 30 33 (16-19) is 鰺 (U+9C3A) in 1978 and 鯵 (U+9BF5) in 1983.
The 1983 revision also added the box-drawing row 8 and four kanji at 84-01 to
84-04; the explorer decodes those cells with their 1983 characters under
ESC $ @ and flags them. It does not know which cells of row 2 (39
special characters were added in 1983) the 1978 set lacked, so it reads row 2 as
1983. Other converters, such as the iconv and browsers, read ESC $ @ as
the 1983 set; RFC 1468 itself notes that some systems do not tell the two apart.
ISO-2022-JP-2 (RFC 1554)
ISO-2022-JP with more sets, so that one message can mix languages: GB 2312, KS C 5601 and two 96-character sets for G2.
| Escape sequence | Bytes | Selects |
|---|---|---|
ESC $ A | 1B 24 41 | GB 2312-80 into G0, two bytes a character |
ESC $ ( C | 1B 24 28 43 | KS C 5601-1987 (KS X 1001) into G0, two bytes a character |
ESC . A | 1B 2E 41 | the high part of ISO 8859-1 into G2 |
ESC . F | 1B 2E 46 | the high part of ISO 8859-7 (Greek) into G2 |
ESC N | 1B 4E | SS2: the next byte, 20 to 7F, is the G2 character with the top bit set |
G2 is empty at the start of every line; an SS2 before an ESC . A or
ESC . F on the same line is an invalid sequence. The KS X 1001 cells
decode through the browser’s EUC-KR (code page 949, which agrees with KS X 1001
except at A2 E8; see the
legacy page),
the GB 2312 cells through GBK, and the Greek set through the browser’s ISO 8859-7.
ISO-2022-JP-3 and ISO-2022-JP-2004 (JIS X 0213)
JIS X 0213 is Japan’s extension of JIS X 0208: two planes of 94 × 94 cells, plane 1 (which holds all of JIS X 0208’s characters) and plane 2. The designations are those of ISO-2022-JP-3, which is ISO-2022-JP plus:
| Escape sequence | Bytes | Selects |
|---|---|---|
ESC $ ( O | 1B 24 28 4F | JIS X 0213:2000 plane 1 |
ESC $ ( P | 1B 24 28 50 | JIS X 0213 plane 2 |
ESC $ ( Q | 1B 24 28 51 | JIS X 0213:2004 plane 1 (ISO-2022-JP-2004): the 2000 plane with ten more cells |
A file that uses ESC $ ( Q is reported as ISO-2022-JP-2004, one that
uses ESC $ ( O or ESC $ ( P as ISO-2022-JP-3, one with the
RFC 1554 sets as ISO-2022-JP-2.
The table is the file jisx0213-2004-std.txt that the explorer reads
from this site, unchanged from
x0213.org (Project
X0213, “JIS X 0213:2004 vs Unicode mapping table”, dated 3 May 2009). Its licence
reads “You can use, modify, distribute this table freely”, with the copyright of
earthian@tama.or.jp, I’O and Project X0213. Twenty-five cells are two code points
(a kana with U+309A, a Latin letter with a tone mark, and the two tone letters
U+02E9 U+02E5 and U+02E5 U+02E9); the explorer shows the characters as one and
says so in the note. Where the file gives an ASCII value and a fullwidth one
(“Fullwidth: U+FF0C” for the comma), the explorer uses the fullwidth value, as
libiconv does. The 11,206 cells of both planes were checked against macOS’s iconv
(EUC-JIS-2004); they agree except the 25 two-code-point cells, which
that iconv cannot decode, and the two cells 21 31 and 21 6F
of plane 1, which the table gives as U+203E and U+00A5 and iconv as U+FFE3 and
U+FFE5. The explorer follows the table.
ISO-2022-KR (RFC 1557)
The designator ESC $ ) C (1B 24 29 43), once, at the
start of a line, selects KS X 1001 (KSC 5601) into G1. Then shift out (SO,
0E) starts two-byte Hangul and hanja, and shift in (SI,
0F) returns to ASCII; SO and SI must pair within a line. Each line
starts in ASCII. The double-byte characters decode through EUC-KR.
ISO-2022-CN and ISO-2022-CN-EXT (RFC 1922)
Designators select a character set for SO or for SS2 (ESC N, for the
next two bytes only). Each line starts in ASCII and must carry its own designations,
and ends in ASCII. The explorer enforces the designations: an SO, SS2 or SS3 on a
line with no designation for it earlier on the same line is an invalid sequence,
not a character read from a default set. (In ISO-2022-KR the one designation at the
top of the file serves every line.)
| Escape sequence | Bytes | Set | Shift | The explorer |
|---|---|---|---|---|
ESC $ ) A | 1B 24 29 41 | GB 2312-80 | SO | decodes (through GBK) |
ESC $ ) G | 1B 24 29 47 | CNS 11643 plane 1 | SO | decodes (through Big5, below) |
ESC $ * H | 1B 24 2A 48 | CNS 11643 plane 2 | SS2 | decodes (through Big5, below) |
ISO-2022-CN-EXT adds GB 12345-90, ISO-IR-165, GB 7589-87, GB 13131-91, GB 7590-87,
GB 13132-91 and CNS 11643 planes 3 to 7, the last five with SS3 (ESC O,
1B 4F), which like SS2 takes the next two bytes only. RFC 1922
leaves the GB sets’ final characters unassigned, “these GB sets shall only be used
once these final characters are assigned”, and they never were. The ones that
exist:
| Escape sequence | Bytes | Set | Shift | The explorer |
|---|---|---|---|---|
ESC $ ) E | 1B 24 29 45 | ISO-IR-165 (GB 2312 with the GB 6345.1 and GB 8565.2 additions) | SO | decodes (from the ICU tables below) |
ESC $ + I | 1B 24 2B 49 | CNS 11643 plane 3 | SS3 | decodes (from the ICU tables below) |
ESC $ + J | 1B 24 2B 4A | CNS 11643 plane 4 | SS3 | decodes (from the ICU tables below) |
ESC $ + K | 1B 24 2B 4B | CNS 11643 plane 5 | SS3 | decodes (from the ICU tables below) |
ESC $ + L | 1B 24 2B 4C | CNS 11643 plane 6 | SS3 | decodes (from the ICU tables below) |
ESC $ + M | 1B 24 2B 4D | CNS 11643 plane 7 | SS3 | decodes (from the ICU tables below) |
A file that uses any of these is reported as ISO-2022-CN-EXT.
CNS 11643 planes 1 and 2. The browser has no CNS 11643 decoder,
but Big5 was built from these two planes: Big5’s 5,401 level 1 hanzi are plane 1’s
hanzi (44 21 to 7D 4B) and its 7,652 level 2 hanzi are
plane 2’s 7,650 (21 21 to 72 44) plus two repeats,
C9 4A and DD FC, in very nearly the same order. The
explorer counts each cell’s position, finds the Big5 code at the same position and
decodes that with the browser’s Big5 decoder. Five hanzi of plane 1 and sixteen
of plane 2 sit elsewhere in CNS order, and the explorer lists them; one, plane 1
76 41, is U+5F5E where the browser’s Big5 has U+5F5D; plane 1’s
symbol rows (21 to 26) follow Big5’s A1 40
onwards with a few changes, and its rows of radicals, kana and control pictures
(27 to 2B, 42) are runs of Unicode. The
result was checked cell by cell against the CNS 11643 table in macOS’s iconv
(EUC-TW), and all 13,945 characters of the two planes agree.
Planes 3 to 7 and ISO-IR-165 have no counterpart in the browser, and their tables (several thousand characters each) are too large to write out by hand. The explorer reads two data files that sit on the site exactly as ICU publishes them, parsing them the first time a file needs them:
euc-tw-2014.ucm, ICU’s table for CNS 11643-2014 planes 1 to 7 as EUC-TW (8E A3to8E A7select planes 3 to 7). Source: the ICU mappings directory, commit 61607c27. Licence: the Unicode licence (Unicode Terms of Use), whose notice the file carries.iso-ir-165.ucm, ICU’s table for ISO-IR-165 (two 7-bit bytes), from the same directory and commit and under the same licence.
Only the exact two-way mappings (the |0 lines) are used. If a cell has
no line the character is invalid. A cell the file cannot supply because the file
cannot be read shows as not decoded.
The result was checked cell by cell against macOS’s iconv (ISO-2022-CN-EXT
for all six sets, 94 × 94 cells each). macOS’s iconv keeps only the low 16 bits of a
code point above U+FFFF (it prints U+2000B as U+000B), so for 24,233 cells of
extension B and the compatibility block the check could confirm those 16 bits and the
plane comes from the ICU table alone. Every other cell agrees except the ones
below, where the two tables differ and the explorer follows ICU’s:
- ISO-IR-165: row
2A(ISO 646-CN, GB 1988-80) and row2B(ASCII), which libiconv does not map; and eight cells of GB 2312’s rows:21 2Bis U+007E (libiconv U+FF5E),21 67U+0024 (U+FF04),21 69U+00A2 (U+FFE0),21 6AU+00A3 (U+FFE1),23 67U+0261 (U+FF47),28 3CU+1E3F (U+E7C7),28 3Fhas no character in ICU’s table (libiconv U+01F9), and28 40is U+FF47 (libiconv U+0261). The registration itself, ISO-IR 165 at the ITSCJ site, is a scanned chart and could not be read to settle these. - CNS 11643: 25 cells of planes 3, 4 and 7, where ICU has the 2014
edition and libiconv an older one. Eight characters moved from plane 3 to plane 4
(for example
3 64 5F, U+5759, is4 23 61in ICU), one moved within plane 4 and a few others differ.
HZ (RFC 1843)
The text starts in ASCII. ~{ switches to GB 2312, two bytes at a time,
first byte 21–77, second 21–7E;
~} switches back to ASCII.
| In ASCII mode | Meaning |
|---|---|
~{ | start GB mode |
~~ | a literal tilde |
~ then a newline | a line continuation: the newline is not part of the text |
~ then anything else | an invalid sequence |
RFC 1843 has no line rule of its own; encoders that keep lines short end GB mode before each line break. The explorer starts each line in ASCII. The GB characters decode through GBK with the top bits set.
Lines
Limits of the viewer. The Text tab shows the first 16 MB of the file (16,777,216 bytes), and says when it has stopped. A row of the Lines table shows the first 1,000 characters of its line, then “…”. Neither limit hides anything from the tree, which holds every line and, inside each line, every character, however long, and the counts cover the whole file.
Names. The character list names every control code, the blank and format characters, and every other assigned code point from the Unicode Character Database’s UnicodeData.txt, version 18.0.0, copied unchanged into the site (Unicode, Inc.’s data under the Unicode Terms of Use); a code point the file does not have is not assigned and gets no name. The characters are the Unicode ones each set maps to; the sets themselves have no names of their own beyond their row and cell.
A line is the bytes up to CR, LF or CR LF, which are never a byte of a two-byte
character (the bytes of those are 21 and above). Characters are counted
as characters, not bytes; escape sequences and shift codes are not counted. Each shift
sequence shows as its own item in the character list.
Line endings
| Name | Bytes |
|---|---|
| LF | 0A |
| CR LF | 0D 0A |
| CR | 0D |
End of the file
The text simply stops. Text encoded correctly returns to ASCII before the end of every line and of the file, as RFC 1468 requires. A line that ends inside a two-byte set is flagged on its last character in the tree, but the file is still read as ISO-2022-JP and the line is not counted as an invalid sequence.
Problems
| Problem | Meaning |
|---|---|
| invalid byte sequence | an escape sequence the explorer does not know; a byte outside 21–7E where a two-byte character should start; an HZ tilde that is not one of the sequences above; or a two-byte form with no character in the table |
| control character | a control other than tab, vertical tab, form feed and the line endings, and the shift codes that the encoding uses |
| mixed line endings | more than one kind of line ending |
Telling it apart
The explorer tries this format before UTF-8, since these files are also valid ASCII.
It accepts a file when every byte is above 00 and below 80,
the file holds one of the escape sequences above, or a ~{ with HZ’s
tilde rules holding throughout, and the two-byte characters reached that way decode,
with no more than one error in every hundred two-byte characters. The escape sequence
decides the encoding: ESC $ ) C is Korean, ESC $ ) A,
G or ESC $ * H Chinese (ISO-2022-CN-EXT when the file also
has ESC $ ) E or one of ESC $ + I to M), and
ESC $ @,
ESC $ B, ESC $ A, ESC . A, ESC . F,
ESC ( J, ESC ( I or one of ESC $ ( B,
@, C, O, P and Q
Japanese.
ESC ( B alone, which terminal programs emit, is not enough.
Not described
The gaps are those on the text overview. For ISO-2022: JIS C
6226-1978 (ESC $ @) is read as the 1983 revision, because the 39 special characters added to row 2
are not identified, and the explorer flags only row 8 and 84-01 to 84-04. The ISO-IR-165 cells where ICU and
libiconv disagree are read as ICU has them.
Variants
- UTF-8 text – one to four bytes a character, ASCII unchanged
- UTF-16LE text – two or four bytes a character, low byte first
- UTF-16BE text – two or four bytes a character, high byte first
- UTF-32LE text – four bytes a character, low byte first
- UTF-32BE text – four bytes a character, high byte first
- Legacy code page text – a pre-Unicode code page that the file does not name
- UTF-7 text – Unicode as pure ASCII, with Base64 runs
- ISO-2022 and HZ text – 7-bit Japanese, Korean and Chinese with escape sequences
- GB18030 text – China’s national encoding, one, two or four bytes a character
- EBCDIC text – IBM mainframe text, not based on ASCII
- SCSU text – Unicode compressed with windows and tags
- BOCU-1 text – Unicode as differences between code points
- UTF-1 text – the withdrawn ISO 10646 transformation
- UTF-EBCDIC text – UTF-8 for EBCDIC systems
Links
Developers
- ICU – conversion between encodings, including ISO-2022 and HZ (C, C++, Java)
- GNU libiconv – the iconv conversion library and command (C)
- encoding_rs – ISO-2022-JP as the WHATWG standard defines it (Rust)