Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 utf16 和 utf32 中,一个字节的零是否意味着 null?就像在 utf8 中一样,还是我们需要 2 和 4 个字节的零来相应地在 utf16 和 utf32 中创建 null?
在 UTF-16 中它将是两个字节,而在 UTF-32 中它将是 4 个字节。
毕竟,否则您无法区分编码值恰好以零字节开头的字符和表示 U+0000 的单个零字节。
基本上 UTF-16 工作在 2 个字节的块中,而 UTF-32 工作在 4 个字节的块中。(诚然,对于BMP 之外的字符,您需要两个“块”的 UTF-16,但原理仍然相同。)如果您要实现 UTF-16 解码器,您将一次读取两个字节。