UTF-8,UTF-16和UTF-32 [英] UTF-8, UTF-16, and UTF-32
问题描述
UTF-8,UTF-16和UTF-32有什么区别?
What are the differences between UTF-8, UTF-16, and UTF-32?
我知道它们都将存储Unicode,并且每个都使用不同数量的字节来表示字符.选择一个而不是另一个有优势吗?
I understand that they will all store Unicode, and that each uses a different number of bytes to represent a character. Is there an advantage to choosing one over the other?
推荐答案
在ASCII字符代表文本块中大多数字符的情况下,UTF-8具有优势,因为UTF-8将这些字符编码为8位(像ASCII).另一个优点是,仅包含ASCII字符的UTF-8文件具有与ASCII文件相同的编码.
UTF-8 has an advantage in the case where ASCII characters represent the majority of characters in a block of text, because UTF-8 encodes these into 8 bits (like ASCII). It is also advantageous in that a UTF-8 file containing only ASCII characters has the same encoding as an ASCII file.
UTF-16在ASCII不占优势的情况下更好,因为它主要每个字符使用2个字节.对于高阶字符,UTF-8将开始使用3个或更多字节,而对于大多数字符,UTF-16将仅保留2个字节.
UTF-16 is better where ASCII is not predominant, since it uses 2 bytes per character, primarily. UTF-8 will start to use 3 or more bytes for the higher order characters where UTF-16 remains at just 2 bytes for most characters.
UTF-32将以4个字节覆盖所有可能的字符.这使它显得肿.我想不出使用它的任何优势.
UTF-32 will cover all possible characters in 4 bytes. This makes it pretty bloated. I can't think of any advantage to using it.
这篇关于UTF-8,UTF-16和UTF-32的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!