为什么 UTF-32 存在,而编码每个字符只需要 21 位? [英] Why UTF-32 exists whereas only 21 bits are necessary to encode every character?

查看:24
本文介绍了为什么 UTF-32 存在,而编码每个字符只需要 21 位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们知道代码点可以在这个区间 0..10FFFF 中,小于 2^21.那么当所有的代码点都可以用 3 个字节表示时,为什么我们需要 UTF-32 呢?UTF-24 应该足够了.

We know that codepoints can be in this interval 0..10FFFF which is less than 2^21. Then why do we need UTF-32 when all codepoints can be represented by 3 bytes? UTF-24 should be enough.

推荐答案

我能想到的两个原因:

  • 它允许未来的扩展
  • (更重要的是)计算机通常更擅长处理 4 字节边界上的数据.与处理 3 字节边界的痛苦相比,减少内存消耗方面的好处相对较小.

我想这有点像问为什么我们经常有 8 位、16 位、32 位和 64 位整数数据类型(byte、int、long 等等)而不是 24 位数据类型.我敢肯定,在很多情况下,我们知道一个数字永远不会超过 221,但是使用 int 比创建 24 位更简单类型.

I guess this is a bit like asking why we often have 8-bit, 16-bit, 32-bit and 64-bit integer datatypes (byte, int, long, whatever) but not 24-bit ones. I'm sure there are lots of occasions where we know that a number will never go beyond 221, but it's just simpler to use int than to create a 24-bit type.

这篇关于为什么 UTF-32 存在,而编码每个字符只需要 21 位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆