Unicode
Unicode有两套标准,一套叫UCS-2(Unicode-16),用2个字节为字符编码,另一套叫UCS-4(Unicode-32),用4个字节为字符编码。
UTF= UCS Transformation Format UCS转换格式
Unicode编码是字符表的映射,他的实现包含了UTF16,UTF8,UTF32
如'回'的Unicode编码是56DE,是一对映射关系。
-
UTF16
UTF16编码使用固定的2个字节来存储。因为是多字节存储,所以它的存储方式分为2种:大端序和小端序。
如'回'的Unicode编码是56DE
-
UTF8

如上面‘回’,对应为000056DE(UCS-4)对应U+ 0000800 - U+0000FFFF,所以‘回’对应的UTF8编码为3个字节,刚好将56DE二进制填入1110xxxx 10xxxxxx 10xxxxxx则为对应UTF8编码
Unicode详细分析
Base64
Base64编码要求把3个8位字节(3*8=24)转化为4个6位的字节(4*6=24),之后在6位的前面补两个0,形成8位一个字节的形式。由于2的6次方为64,所以每6个位为一个单元,对应某个可打印字符。当原数据不是3的整数倍时,如果最后剩下两个输入数据,在编码结果后加1个“=;如果最后剩下一个输入数据,编码结果后加2个“=;如果没有剩下任何数据,就什么都不要加,这样才可以保证资料还原的正确性。




网友评论