在C#BinaryReader.ReadString 7位格式编码的整数 [英] Encoding an integer in 7-bit format of C# BinaryReader.ReadString

查看:1497
本文介绍了在C#BinaryReader.ReadString 7位格式编码的整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C# BinaryReader在有一个功能可根据MSDN,读取一个整数连接codeD作为七位整数,然后读取一个字符串,这个整数的长度。

C#'s BinaryReader has a function that according to MSDN, reads an integer encoded as "seven bit integer", and then reads a string with the length of this integer.

是否有一个清晰的文档七位整数格式(我有一个大概的了解了MSB或LSB商标是否有更多的要读取的字节,其余位是数据,但我会很高兴的一些更精确的)。

Is there a clear documentation for the seven bit integer format (I have a rough understanding that the MSB or the LSB marks whether there are more bytes to read, and the rest bits are the data, but I'll be glad for something more exact).

更妙的是,有没有在这个格式的 C 执行读取和写入的数字?

Even better, is there a C implementation for reading and writing numbers in this format?

推荐答案

那么,对于<一个文件href="http://msdn.microsoft.com/en-us/library/system.io.binaryreader.read7biten$c$cdint.aspx">BinaryReader.Read7BitEn$c$cdInt已经表示,它预计将被写入BinaryWriter.Write7BitEn$c$cdInt并且该方法的文档详细的格式为:

Well, the documentation for BinaryReader.Read7BitEncodedInt already says, that it expects the value to be written with BinaryWriter.Write7BitEncodedInt and that method documentation details the format:

value参数的整数写出七位的时间,开始的7个最低-显著位。一个字节的最高位表示是否有更多的字节写入后,这一个。

The integer of the value parameter is written out seven bits at a time, starting with the seven least-significant bits. The high bit of a byte indicates whether there are more bytes to be written after this one.

如果值将适合在七位,它需要的空间只有一个字节。如果值将不适合在七个位中,高位被设置在第一字节和写出。值然后由七比特移位和下一个字节被写入。重复这一过程,直到整个整数已被写入。

If value will fit in seven bits, it takes only one byte of space. If value will not fit in seven bits, the high bit is set on the first byte and written out. value is then shifted by seven bits and the next byte is written. This process is repeated until the entire integer has been written.

所以整数1259551277,二进制1001011000100110011101000101101将被转换成7位格式如下:

So the integer 1259551277, in binary 1001011000100110011101000101101 will be converted into that 7-bit format as follows:

Remaining integer                 encoded bytes
1001011000100110011101000101101
100101100010011001110100          00101101
10010110001001100                 10101101 01110100
1001011000                        10101101 11110100 01001100
100                               10101101 11110100 11001100 01011000
0                                 10101101 11110100 11001100 11011000 00000100

我没那么有信心在我的C技能,现在提供一个工作的实施,虽然。但它不是很难做到,基于这样的描述。

I'm not that confident in my C skills right now to provide a working implementation, though. But it's not very hard to do, based on that description.

这篇关于在C#BinaryReader.ReadString 7位格式编码的整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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