在压缩一系列的零和零

时间:2011-03-03 08:41:33

标签: c data-compression

我需要像这样压缩一系列的1和0

http://cid-f328e92ab80e3d64.office.live.com/self.aspx/.Public/bits.txt

任何人都可以建议我使用什么编码器来实现最佳压缩(霍夫曼,算术,BWT,LZW,RLE,PAQ ......)

感谢任何帮助,并提前感谢您。

尊重, 查克

P.S。我发现bwtmix下降到577字节,但它是用c ++编写的,我需要它在c。

1 个答案:

答案 0 :(得分:0)

这个Python程序通过简单地将1和0转换为字节,将其压缩到715字节,包括16位前导计数。不幸的是,然后标准压缩程序zip,gzip和bzip2似乎无法再从中获得压缩。


import sys, struct
i, n, b, count = 0, 0, '', 0
for byte in open('/tmp/binary.txt').read().rstrip():
 n = (n << 1) | (ord(byte) & 1)
 i = (i + 1) % 8
 if i == 0:
  n, b = 0, b + chr(n)
 count += 1
sys.stdout.write(struct.pack('<h', count) + b)