由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 怎么把 integer 转为 multi-byte integer format?
相关主题
什么是 multi-byte string?how to login mitbbs with java code (转载)
大家来看看这个纯Javascript实现的QR二维码生成器请教:如何用Java get URL content是.swe并且是utf-16 encoding的文件
求教, python 对于很奇怪的字符的encoding 怎么处理?编码问题
用react的试过中文么?顺便问一个CreateFile问题 (转载)
encode high cardinality categorical featuresGoogle Chrome 里还是夹带了私货
a question about CGI sucks (转载)
How to encode YYYY-MM-DD?[合集] how to know the encoding of a file
请教:JavaScript怎么复制一个node(含子节点)? (转载)how to get client locale inside the running application?
相关话题的讨论汇总
话题: integer话题: byte话题: 0xa0话题: 0x20话题: 转为
进入Programming版参与讨论
1 (共1页)
M*******8
发帖数: 85
1
下面的例子是怎么把0xA0 转为 0x81 和 0x20 的? 看不懂, 能不能给讲讲, 谢谢
How to transfer an integer to multi-byte integer format?
For example, the integer value 0xA0 would be encoded with the two-byte
sequence 0x81 0x20. The integer value 0x60 would be encoded with the one-
byte sequence 0x60.
D****A
发帖数: 360
2
interesting. 估计是每个byte取一位做连接符, 是1就看下一个byte否则结束
每个byte只有7位有效位,两个byte应该能表示一个integer的低14位
0xA0=10100000
0x81=10000001
0x20=00100000
因为一个byte只能encode7位,所以0xA0的最高位1应该在0x81里的有效最低位,
另外0xA0的低7位应该在0x20里,0xA0和0x20的低七位相通,说明这种encoding
把每个byte的最高位用做连接符了
综上转换公式应该是 do x = (x << 7)|(b[i] & 0x7f) until (b[i] & 0x80) == 0

【在 M*******8 的大作中提到】
: 下面的例子是怎么把0xA0 转为 0x81 和 0x20 的? 看不懂, 能不能给讲讲, 谢谢
: How to transfer an integer to multi-byte integer format?
: For example, the integer value 0xA0 would be encoded with the two-byte
: sequence 0x81 0x20. The integer value 0x60 would be encoded with the one-
: byte sequence 0x60.

M*******8
发帖数: 85
3
多谢指点!
这个
do x = (x << 7)|(b[i] & 0x7f) until (b[i] & 0x80) == 0
是从multi-byte integer format转为regular integer 吧?
如何从integer转为 multi-byte integer format? 谢谢

【在 D****A 的大作中提到】
: interesting. 估计是每个byte取一位做连接符, 是1就看下一个byte否则结束
: 每个byte只有7位有效位,两个byte应该能表示一个integer的低14位
: 0xA0=10100000
: 0x81=10000001
: 0x20=00100000
: 因为一个byte只能encode7位,所以0xA0的最高位1应该在0x81里的有效最低位,
: 另外0xA0的低7位应该在0x20里,0xA0和0x20的低七位相通,说明这种encoding
: 把每个byte的最高位用做连接符了
: 综上转换公式应该是 do x = (x << 7)|(b[i] & 0x7f) until (b[i] & 0x80) == 0

D****A
发帖数: 360
4
查信

【在 M*******8 的大作中提到】
: 多谢指点!
: 这个
: do x = (x << 7)|(b[i] & 0x7f) until (b[i] & 0x80) == 0
: 是从multi-byte integer format转为regular integer 吧?
: 如何从integer转为 multi-byte integer format? 谢谢

1 (共1页)
进入Programming版参与讨论
相关主题
how to get client locale inside the running application?encode high cardinality categorical features
What's the problem with 'ascii' codec? (转载)a question about CGI
how to encoding UTF-8 to hexHow to encode YYYY-MM-DD?
c#里面没有HttpUtility这个成员,咋怎?请教:JavaScript怎么复制一个node(含子节点)? (转载)
什么是 multi-byte string?how to login mitbbs with java code (转载)
大家来看看这个纯Javascript实现的QR二维码生成器请教:如何用Java get URL content是.swe并且是utf-16 encoding的文件
求教, python 对于很奇怪的字符的encoding 怎么处理?编码问题
用react的试过中文么?顺便问一个CreateFile问题 (转载)
相关话题的讨论汇总
话题: integer话题: byte话题: 0xa0话题: 0x20话题: 转为