27

可能重复:
为什么存在 UTF-32 而编码每个字符只需要 21 位?

UTF-32 中的最大 Unicode 代码点为 0x10FFFF。UTF-32 有 21 个信息位和 11 个多余的空白位。那么为什么没有 UTF-24 编码(即去掉高字节的 UTF-32)将每个代码点存储在 3 个字节而不是 4 个字节中呢?

4

1 回答 1

26

好吧,事实是:UTF-24 是在 2007 年提出的:

http://unicode.org/mail-arch/unicode-ml/y2007-m01/0057.html

提到的优点和缺点是:

"UTF-24 
Advantages: 
 1. Fixed length code units. 
 2. Encoding format is easily detectable for any content, even if mislabeled. 
 3. Byte order can be reliably detected without the use of BOM, even for single-code-unit data. 
 4. If octets are dropped / inserted, decoder can resync at next valid code unit. 
 5. Practical for both internal processing and storage / interchange. 
 6. Conversion to code point scalar values is more trivial then for UTF-16 surrogate pairs 
    and UTF-7/8 multibyte sequences. 
 7. 7-bit transparent version can be easily derived. 
 8. Most compact for texts in archaic scripts. 
Disadvantages: 
 1. Takes more space then UTF-8/16, except for texts in archaic scripts. 
 2. Comparing to UTF-32, extra bitwise operations required to convert to code point scalar values. 
 3. Incompatible with many legacy text-processing tools and protocols. "

正如 David Starner 在http://www.mail-archive.com/unicode@unicode.org/msg16011.html中指出的那样:

为什么?UTF-24 几乎总是会比 UTF-16 大,除非您正在谈论旧斜体或哥特体的文档。数学字母数字字符几乎总是与足够的 ASCII 组合以使 UTF-8 获胜,如果没有,则有足够的 BMP 字符以使 UTF-16 获胜。现代计算机不能很好地处理 24 位块。在内存中,它们会占用 32 位,除非您声明它们已打包,然后它们会比 UTF-16 或 UTF-32 慢很多。如果您要存储到磁盘,您还可以使用 BOCU 或 SCSU(您已经使用非标准),或者使用 UTF-8、UTF-16、BOCU 或 SCSU 的标准压缩。压缩后的 SCSU 或 BOCU 应该占用 UTF-24 的一半空间,如果那样的话。

您还可以查看以下 StackOverflow 帖子:

为什么存在 UTF-32 而编码每个字符只需要 21 位?

于 2012-04-13T15:36:54.813 回答