I have written a piece of code to add a '0' after 6 consecutive '1' in a bit stream. But how to decode it?
Here an example of one bits stream:
original = {01101111110111000101111110001100...etc...}
stuffed = {011011111O101110001011111O10001100...etc...}
(The 'O
' stand for the stuffed '0
'.)
As you can see a '0' was added after each '111111' and to retrieve the original stream one has to remove it. Easy.
But... What if the original stream had the same form as the stuffed one? How do I know if I have to remove these bits?!
I think you are confused with the basics. Pretend you want a B added after 2 As. This is not 'stuffed':
'Stuffing' it gives you:
The above is either 'stuffed' or 'not stuffed'. In other words you can stuff it again:
Or you could 'unstuff' it:
So if a bitstream has 10 consecutive 1s in it then it has clearly not been stuffed. You can't say the same for a bitstream that could have been stuffed.