社区
消息协作
帖子详情
请美丽、善良、大方、随和、温柔的kitty进来!
zhjian6
2004-04-29 04:39:31
http://expert.csdn.net/Expert/topic/2974/2974400.xml?temp=.3102991
这个问题!
...全文
76
6
打赏
收藏
请美丽、善良、大方、随和、温柔的kitty进来!
http://expert.csdn.net/Expert/topic/2974/2974400.xml?temp=.3102991 这个问题!
复制链接
扫一扫
分享
举报
写回复
配置赞助广告
用AI写文章
6 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
kitty61
2004-04-29
打赏
举报
回复
呵呵,是啊,智慧一小点、美丽多一点。
zhjian6
2004-04-29
打赏
举报
回复
厉害,果然是,美丽与智慧并存!
kitty61
2004-04-29
打赏
举报
回复
UTF8并不算是一种电脑编码,而是一种储存和传送的格式,如前所述,每个Unicode/UCS字符都以 2或4个bytes来储存,看看以下的比较:
以"I am Chinese"为例
用ANSI储存:12 Bytes
用Unicode/UCS2储存:24 Bytes + 2 Bytes(header)
用UCS4储存:48 Bytes + 4 Bytes(header)
以"我是中国人"为例
用ANSI储存:10 Bytes
用Unicode/UCS2储存:10 Bytes + 2 Bytes(header)
用UCS4储存:20 Bytes + 4 Bytes(header)
由此可见直接以Unicode/UCS的原始形式来储存是一种极大的浪费,而且也不利于互联网的传输(中文稍为合算一点^_^)。
有见及此,Unicode/UCS的压缩形式--UTF8出现了,套用官方网站的首句话『UTF-8 stands for Unicode Transformation Format-8. It is an octet (8-bit) lossless encoding of Unicode characters.』,由于UTF也适用于编码UCS,故亦可称为『UCS transformation formats (UTF)』
UTF8是以8bits即1Bytes为编码的最基本单位,当然也可以有基于16bits和32bits的形式,分别称为UTF16和UTF32,但目前用得不多,而UTF8则被广泛应用在文件储存和网络传输中。
编码原理
先看这个模板:
UCS-4 range (hex.) UTF-8 octet sequence (binary)
0000 0000-0000 007F 0xxxxxxx
0000 0080-0000 07FF 110xxxxx 10xxxxxx
0000 0800-0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx
0001 0000-001F FFFF 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
0020 0000-03FF FFFF 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
0400 0000-7FFF FFFF 1111110x 10xxxxxx ... 10xxxxxx
编码步骤:
1) 首先确定需要多少个8bits(octets)
2) 按照上述模板填充每个octets的高位bits
3) 把字符的bits填充至x中,字符顺序:低位→高位,UTF8顺序:最后一个octet的最末位x→第一个octet最高位x
4) 解码的原理一样。
实例:(留意每个bit的颜色,粗体字为模板内容)
UCS-4 UTF-8
HEX BIN Bytes BIN HEX Bytes
0000 000A 00001010 4 00001010 0A 1
0000 0099 10011001 4 11000010 10011001 C2 99 2
0000 8D99 10001101 10011001 4 11101000 10110110 10011001 E8 B6 99 3
不知大家看懂了没有,其实不懂也无所谓,反正又不用自己算,程式可以完全代劳。
以UTF8格式储存的文件档首标识为EF BB BF。
效率
从上述编码原理中得出的结论是:
1.每个英文字母、数字所占的空间为1 Byte;
2.泛欧语系、斯拉夫语字母占2 Bytes;
3.汉字占3 Bytes。
由此可见UTF8对英文来说是个非常诱人的方案,但对中文来说则不太合算,无论用ANSI还是 Unicode/UCS2来编码都只用2 Bytes,但用UTF8则需要3 Bytes。
以下是一些统计资料,显示用UTF8来储存文件每个字符所需的平均字节:
1.拉丁语系平均用1.1 Bytes;
2.希腊文、俄文、阿拉伯文和希伯莱文平均用1.7 Bytes;
3.其他大部份文字如中文、日文、韩文、Hindi(北印度语)用约3 Bytes;
4.用超过4 Bytes的都是些非常少用的文字符号。
zhjian6
2004-04-29
打赏
举报
回复
UTF8编码是什么原理?
kitty61
2004-04-29
打赏
举报
回复
呵呵,这还差不多^-^
kitty61
2004-04-29
打赏
举报
回复
是UFT8编码
Project Euler:Problem 88 Product-sum numbers
A natural number, N, that can be written as the sum and product of a given set of at least two natural numbers, {a1, a2, ... , ak} is called a product-sum number: N = a1 + a2 + ... + ak = a1 × a2 ×
Project Euler:Product-sum numbers (problem 88) C++
A natural number, N, that can be written as the sum and product of a given set of at least two natural numbers, {a1, a2, ... , ak} is called a product-sum number: N = a1 + a2 + ... + ak = a1 × a2...
Project Euler 88:Product-sum numbers 积和数
Product-sum numbers A natural number, N, that can be written as the sum and product of a given set of at least two natural numbers, {a1, a2, … , ak} is called a product-sum number: N = a1 + a2 + … + ...
project euler 解题
project euler 3:Any integer greater than 1 is either a prime number, or can be written as a unique product of prime numbers (ignoring the order). 每一个数都能表示成质数的乘积。 const long numm = 600851475143; lo
Project Euler 题解
这个方阵不太方便直接弄到程序里,所以当做输入数据就可以了。会超时,但是实际上远远跑不满,所以直接枚举。直接枚举直接枚举直接枚举。怎么前面的题都是无脑题啊?拉插一下就可以得到题目中所说的“最优多项式” 了。我写的是高精度,代码比较长,题目很简单,就不贴了。注意不一定第一个比第二个大,要取绝对值。直接写一个高精度,或者用 Python 即可。猜一波小的质数不会太大,于是直接枚举。那么可以使用 C++ 自带的(从。算出来,然后直接对着每个。最后可能是个大质数。函数将数转成字符串。
消息协作
536
社区成员
39,094
社区内容
发帖
与我相关
我的任务
消息协作
企业开发 Exchange Server
复制链接
扫一扫
分享
社区描述
企业开发 Exchange Server
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章