根据维基百科UTF-8页面,我从人们那里听到了相互矛盾的观点。

它们是一样的,不是吗?有人能澄清一下吗?


当前回答

它们是一样的,不是吗?

不,他们不是。


我认为你引用的维基百科页面的第一句话给出了一个很好的,简短的总结:

UTF-8是一种可变宽度字符编码,能够使用一到四个8位字节编码Unicode中的所有1,112,064个有效代码点。

阐述:

Unicode is a standard, which defines a map from characters to numbers, the so-called code points, (like in the example below). For the full mapping, you can have a look here. ! -> U+0021 (21), " -> U+0022 (22), \# -> U+0023 (23) UTF-8 is one of the ways to encode these code points in a form a computer can understand, aka bits. In other words, it's a way/algorithm to convert each of those code points to a sequence of bits or convert a sequence of bits to the equivalent code points. Note that there are a lot of alternative encodings for Unicode.


乔尔给出了一个非常好的解释,并概述了这里的历史。

其他回答

1. Unicode

有很多世界各地的字符,如“$,& h,, t, ?,张,1 = +……”。

然后出现了一个致力于这些角色的组织,

他们制定了统一码标准。

标准如下:

创建一个表单,其中每个位置都称为“代码点”或“代码位置”。 整个位置从U+0000到U+10FFFF; 到目前为止,有些位置被字符填充,有些位置被保存或为空。 例如,位置“U+0024”被字符“$”填充。

PS:当然,还有另一个叫做ISO的组织维护着另一个标准——“iso10646”,几乎是一样的。

2. utf - 8

如上所述,U+0024只是一个位置,所以我们不能将“U+0024”在电脑中保存为字符“$”。

必须有一种编码方法。

然后是编码方法,如UTF-8,UTF-16,UTF-32,UCS-2....

在UTF-8下,代码点“U+0024”被编码为00100100。

00100100是我们在计算机中为“$”保存的值。

现有的答案已经解释了很多细节,但这里有一个非常简短的答案,有最直接的解释和例子。

Unicode是将字符映射到码点的标准。 每个字符都有一个唯一的编码点(识别号),它是一个像9731这样的数字。

UTF-8是码点的编码。 为了将所有字符存储在磁盘上(在文件中),UTF-8将字符分成最多4个八位字节(8位序列)-字节。 UTF-8是几种编码(表示数据的方法)之一。例如,在Unicode中,(十进制)码位9731表示一个雪人(☃),它在UTF-8中由3个字节组成:E2 98 83

这是一个排序的列表,其中有一些随机的例子。

Unicode是与ISO/IEC 10646一起定义通用字符集(UCS)的标准,UCS是表示几乎所有已知语言所需的所有现有字符的超集。

Unicode为其存储库中的每个字符分配一个名称和一个数字(字符代码或代码点)。

UTF-8编码,是一种在计算机内存中以数字方式表示这些字符的方法。UTF-8将每个码位映射到一个八字节序列(8位字节)

,例如,

UCS字符= Unicode字符

UCS代码点= U+24B62

UTF-8 encoding = F0 A4 AD A2 (hex) = 11110000 10100100 10101101 10100010 (bin)

UTF-8是Unicode文本的一种可能的编码方案。

Unicode是一个范围广泛的标准,它定义了超过140,000个字符,并为每个字符分配一个数字代码(一个码位)。它还定义了如何对文本进行排序、规范化、更改大小写等规则。Unicode中的字符由一个从0到0x10FFFF(包括0x10FFFF)的码位表示,但有些码位是保留的,不能用于字符。

将一串Unicode码位编码成二进制流的方法不止一种。这些被称为“编码”。最直接的编码是UTF-32,它将每个代码点存储为32位整数,每个整数宽为4字节。因为代码点最多只能到0x10FFFF(需要21位),所以这种编码有点浪费。

UTF-8是另一种编码,由于与UTF-32和其他编码相比有许多优点,它正在成为事实上的标准。UTF-8将每个码位编码为1、2、3或4个字节值的序列。ASCII范围内的码位被编码为一个单字节值,以便与ASCII兼容。超出这个范围的代码点分别使用2、3或4个字节,这取决于它们所在的范围。

UTF-8在设计时考虑了这些属性:

ASCII characters are encoded exactly as they are in ASCII, such that an ASCII string is also a valid UTF-8 string representing the same characters. More efficient: Text strings in UTF-8 almost always occupy less space than the same strings in either UTF-32 or UTF-16, with just a few exceptions. Binary sorting: Sorting UTF-8 strings using a binary sort will still result in all code points being sorted in numerical order. When a code point uses multiple bytes, none of those bytes contain values in the ASCII range, ensuring that no part of them could be mistaken for an ASCII character. This is also a security feature. UTF-8 can be easily validated, and distinguished from other character encodings by a validator. Text in other 8-bit or multi-byte encodings will very rarely also validate as UTF-8 due to the very specific structure of UTF-8. Random access: At any point in a UTF-8 string it is possible to tell if the byte at that position is the first byte of a character or not, and to find the start of the next or current character, without needing to scan forwards or backwards more than 3 bytes or to know how far into the string we started reading from.

作为一个直截了当的简单回答:

Unicode是一种表示多种人类语言字符的标准。 UTF-8是一种编码Unicode字符的方法。


是的:我故意忽略了UTF-8的内部工作原理。