不寻常的整数编码字节 - 什么方案呢? [英] Unusual Integer encoding to bytes - what scheme is this?

查看:211
本文介绍了不寻常的整数编码字节 - 什么方案呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么整数编码方案来实现以下,以及我们如何能做到这一点。NET中:

  127 = 7F
128 = 8001
255 = FF01
256 = 8002
500 = F403
 

解决方案

不是很确定它有一个正式的名称,它是一个7位编码。它是一个可变长度编码,一个字节的高位如果另一个字节如下设置。字节顺序是little-endian的。

的<一个href="http://referencesource.microsoft.com/#mscorlib/system/io/binarywriter.cs,2daa1d14ff1877bd">.NET框架使用它,Write7BitEn codedInt()方法。所用的BinaryWriter.WriteString()方法,这样可以节省空间,因为最实际的字符串有少于128个字符。

所以F403 => 03F4 => | 0000011 | 1110100 | => | 00000001 | 11110100 | => 0x1F4 == 500

What Integer encoding scheme is used to achieve the following, and how can we do this in .Net:

127 = 7F
128 = 8001
255 = FF01
256 = 8002
500 = F403

解决方案

Not so sure it has an official name, it is a 7-bit encoding. It is a variable length encoding, the high bit of a byte is set if another byte follows. Byte order is little-endian.

The .NET Framework uses it, Write7BitEncodedInt() method. Used by the BinaryWriter.WriteString() method, it saves space since most practical strings have less than 128 characters.

So F403 => 03F4 => |0000011|1110100| => |00000001|11110100| => 0x1F4 == 500

这篇关于不寻常的整数编码字节 - 什么方案呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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