I have a function that compresses a given bitstream in Python, using Run Length Encoding (RLE). I want to now be able to decompress that compressed bitstream. This is my code to compress the bitstream.
def RLEC(inputstream):
count = ""
result = ""
prev_char = ""
for i in range(len(inputstream)):
if inputstream[i] != prev_char:
result = result + str(count) + prev_char
prev_char = inputstream[i]
count = 1
else:
count += 1
else:
result += str(count) + prev_char
return result
If I compress the bitstream, for example 0111111111111111111111111110 would be compressed as 1026110. How would I be able to decompress that to give me my original answer? Or at least be able to split the numbers into sections, each telling how many bits I have and what bit it is? If this is wrong, what format should I use to maximise bitstream efficiency and be able to decompress/split into separate sections?