LZW compression - converting a string binary into bits
Posted on 2003-03-06
I am using LZW as the compression algorithm, that part works fine, but I am trying to convert a binary string of a codeword into bits as to compress the file further.
Here is an example:
Input from file: ababababababbbabac
codeword ( eg ): 12344634
binary for the codeword ( not correct just example )
Lets assume that the alphabet consists of the 127 ASCII characters from decimal code 0 to decimal code 126 (tilde), inclusive. Therefore, I will need at least 7 bits per code initially. So how can i convert each element in the binary representation to a bit, and lets say enter into a 7 bit stream? Also how can I read it back, i.e how do i know what each integer bit was entered at and that it doesnt come back as one big long number that cant be broken up into one byte when decompressing?
Thanks any help would be greatly appreciated
i have seen this done in C.