Reputation: 23
I've made a program which generate a Huffman's Codes from input file. Now I don't know how to end output file(which should be compressed based on the input file and generated codes). Lets say that we have 43 bits to save so how end the file? I can simply add 5 zeros in the end, but then codes could be wrong. Any ideas? PS Sorry for my bad English.
Upvotes: 0
Views: 395
Reputation: 18109
From wikipedia:
In any case, since the compressed data can include unused "trailing bits" the decompressor must be able to determine when to stop producing output. This can be accomplished by either transmitting the length of the decompressed data along with the compression model or by defining a special code symbol to signify the end of input (the latter method can adversely affect code length optimality, however).
Upvotes: 1
Reputation: 45568
There are two ways to solve this that I can think of:
Upvotes: 1