Reputation: 49
I have generated the codes for different symbol in a file using shannon fano algorithm. Now my problem is that how i will store these codes into file (as file is in byte) so that while reading, reader can assure that at some point, it is the end of code for a particular symbol. So that extra code will not be read.
Upvotes: 1
Views: 4449
Reputation: 6162
First, you can use bitwise operations to read a variable number of bits (not multiple of 8) from a byte array.
Second, if the code is a valid Prefix code, which satisfies
there is no valid code word in the system that is a prefix (start) of any other valid code word in the set
then you can determine where the code ends by comparing the prefix with a table.
Usually, this is done in the following manner:
Upvotes: 3