代理对如何计算? [英] How are surrogate pairs calculated?
问题描述
如果unicode使用17位代码点,则如何从代码点计算代理对?
If a unicode uses 17 bits codepoints, how the surrogate pairs is calculated from code points?
推荐答案
Unicode代码点是标量值,范围从0x000000到0x10FFFF.因此,它们是21位整数,而不是17位.
Unicode code points are scalar values which range from 0x000000 to 0x10FFFF. Thus they are are 21 bit integers, not 17 bit.
代理对是UTF-16形式的一种机制.它代表一个或两个16位代码单元表示21位标量值.
Surrogate pairs are a mechanism of the UTF-16 form. This represents the 21-bit scalar values as one or two 16-bit code units.
- 从0x000000到0x00FFFF的标量值表示为单个16位代码单元,从0x0000到0xFFFF.
- 从0x00D800到0x00DFFF的标量值不是Unicode中的字符,因此它们永远不会出现在Unicode字符串中.
- 从0x010000到0x10FFFF的标量值表示为两个16位代码单元.第一个代码单元将标量值的高11位编码为范围从0xD800-0xDBFF的代码单元.将0x01-0x10的值编码为四位有点棘手.第二个代码单元将标量值的低10位编码为范围从0xDC00-0xDFFF的代码单元.
在Unicode联盟的FAQ中,用示例代码对此进行了详细说明, UTF-8 ,UTF-16,UTF-32& BOM .该FAQ指的是Unicode标准的部分,其中有更多详细信息.
This is explained in detail, with sample code, in the Unicode consortium's FAQ, UTF-8, UTF-16, UTF-32 & BOM. That FAQ refers to the section of the Unicode Standard which has even more detail.
这篇关于代理对如何计算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!