不寻常的整数编码字节 - 什么方案呢?整数、字节、寻常、方案

2023-09-05 00:16:30 作者:做你怀中猫

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

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

解决方案

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

的.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
long类型几个字节,VB问题VB有哪几种数据类型

解决方案

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