Compressing data in-place saves a hell of a lot of memory. How about using the stack to store the length and value of the current run? That way, you don't have to worry about it starting with 0x9B. If you think it's too difficult, I can make the changes a little later.