I'm implementing a huffman library, and for now I have the results of encoding as strings. I want to serialize the tree along with the message, and my result is kinda this:
Message: aabbccdd
Tree output: 001011000011011000100101100011101100100
Encoded message: 0000010110101111
Serialized message (tree + message): 0010110000110110001001011000111011001000000010110101111
As second step, I wanted to turn these binary strings to byte array. The problem is that the number of bits is not necessary suitable to do so: there may be some extra bits. The question is how can I do to convert the final output to a byte array and being able to deserialize it?
The tree is encoded as here described: Efficient way of storing Huffman tree