关于文字代码(character code)

来源:互联网 发布:淘宝手机旺铺 编辑:程序博客网 时间:2024/05/16 17:56
为了理解计算机处理文字的编码/表示,首先需要分清楚三个概念(这些概念经常被混淆)。

1,character repertoire (字符列表)
这是指某个特定的可表示的字符集合。

例如:
the Japanese syllabaries and ideographs of JIS X 0208 (CS 01058) [fixed]
the Western European alphabets and symbols of Latin-1 (CS 00697) [fixed]
the POSIX portable character repertoire [fixed]
the IBM host Japanese repertoire (CS 01001) [fixed]
the Windows Western European repertoire [open]
the Unicode/10646 repertoire [open]

2, character code (字符代码)
把character repertoire中的每一个字符分别赋予一个非负的数字,建立一个字符与数字的一一对应关系。这些数字就是character code。

character code中的数字并不一定是连续的,事实上,有些数字可以被保留作为control function (控制代码)。

character code有很多别名:code position,code number, code value, code element, code point, code set value , code

例如:JIS X 0208, ISO 8859-1,ISO 8859-2, ISO 8859-n, UNICODE等等

3,character encoding (字符编码)
把一个字符串相对应的character codes转换成计算机中的一串字节流的method/algorithm(方法/算法)称为character encoding。

例如:JIS ENCODING, EUC ENCODING, ISO 8859-1,ISO 8859-2, ISO 8859-n, UTF-16, UTF-8等等

这三个概念是分开的,他们之间可以是一对多的关系。比如,同一个character repertoire可以有不同的character codes;同一个 character repertoire/character codes 可以采取不同的character encoding。不过,有些标准同时规定了character repertoire/character codes/character encoding,建立了一一对应的关系,比如ISO 8859,Windows CodePages 等等。

★ Windows CodePages跟ISO 8859并不完全相等,DOS CodePages (OEM CodePages)差别更大。
★ ISO 2022 和 ISO 4873 为 8bits/7bits codes 建立了一个encoding的通用框架(general framework),很多标准都遵从这个框架(当然,一般只是框架中的一个子集);但Windows CodePages并不遵从这个框架。
 
参考资料:
http://www.cs.tut.fi/~jkorpela/chars.html
http://www.unicode.org/unicode/reports/tr17/
http://euc.jp/i18n/charcode.ja.html