使用C#压缩数据 [英] Compressing data using c#
问题描述
你好,
我需要编写游程编码逻辑"用于字节输入.
///例如,aaaaaaabbbbccccddddd将被编码为
///
///7a4b4c5d
///
以下逻辑对实现这一目标有意义吗?
--------------------------------------------------- -------------------------------------------------- ---------------
对于字节输入,例如:
新字节[] {0x01、0x01、0x01、0x02、0x01、0x03、0x01、0x04}
公共字节[]编码(原始字节[])
{
byte runLength;
List< byte> dest = new List< byte>();
为(int i = 0; i< original.Length; i ++)
{
runLength = 1;
while(runLength< byte.MaxValue
&&我+1原始长度.
&& original [i] == original [i + 1])
{
runLength ++;
i ++;
}
dest.Add(runLength);
dest.Add(original [i]);
}
return dest.ToArray();
}
上面有任何建议吗?谢谢.
Hello,
I need to write "run length encoding logic" for byte inputs.
/// For example, aaaaaaabbbbccccddddd would be encoded as
///
/// 7a4b4c5d
///
Does the following logic make sense to achieve this?
----------------------------------------------------------------------------------------------------------------
For e.g.byte input could be like:
new byte[]{0x01, 0x01, 0x01, 0x02, 0x01, 0x03, 0x01, 0x04}
public byte[] Encode(byte[] original)
{
byte runLength;
List<byte> dest = new List<byte>();
for (int i = 0; i < original.Length; i++)
{
runLength = 1;
while (runLength < byte.MaxValue
&& i + 1 < original.Length
&& original[i] == original[i + 1])
{
runLength++;
i++;
}
dest.Add(runLength);
dest.Add(original[i]);
}
return dest.ToArray();
}
Any suggestion on above please?Thanks.
这篇关于使用C#压缩数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!