utf-8 null 与 utf-16/utf-32 null 相同吗?
在 utf16 和 utf32 中,一个字节的零是否表示 null?就像在 utf8 中一样,还是我们需要 2 和 4 个字节的零来相应地在 utf16 和 utf32 中创建 null ?
Does one byte of zeros mean null in utf16 and utf32? as in utf8 or do we need 2 and 4 bytes of zeros to create null in utf16 and utf32 correspondingly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 UTF-16 中它是两个字节,在 UTF-32 中它是 4 个字节。
毕竟,否则您无法区分编码值恰好以零字节开头的字符和表示 U+0000 的单个零字节。
基本上,UTF-16 以 2 字节的块工作,UTF-32 以 4 字节的块工作。 (诚然,对于 BMP 之外的字符,您需要两个 UTF-16“块”,但原理仍然相同。)如果要实现 UTF-16 解码器,您需要读取两个一次字节。
In UTF-16 it would be two bytes, and in UTF-32 it would be 4 bytes.
After all, otherwise you couldn't differentiate between a character whose encoded value just happened to start with a zero byte and a single zero byte representing U+0000.
Basically UTF-16 works in blocks of 2 bytes, and UTF-32 works in blocks of 4 bytes. (Admittedly for characters outside the BMP you need two "blocks" of UTF-16, but the principle is still the same.) If you were to implement a UTF-16 decoder, you'd read two bytes at a time.