Reputation: 11
I created a compressor for my online course project using huffman algorithm. Problem is that the output file in binary (10101010011..
) is bigger than the original files.
Teachers on the course don't know the answer.
I use this, where ciph_text
is a string of 0s and 1s.
with open(full_name,'w') as temp:
temp.write(ciph_text)
Any idea?
I can post more code if requested.
Upvotes: 0
Views: 453
Reputation: 726
int(x, 2) is your friend:
>>> a="00001010000101000001111000101000"
>>> for b in range(0, len(a), 8):
... print a[b:b+8], int(a[b:b+8], 2)
...
00001010 10
00010100 20
00011110 30
00101000 40
Upvotes: 1