Reading — step 1 of 5
Read
~1 min readHuffman Coding
Huffman Encoding
Once you have the code table, encoding is just table lookup + bit packing:
python
Two practical concerns:
Bit packing: codes are bit-strings of varying length, but storage is in 8-bit bytes. Pack with a shift register:
python
Codebook storage: the decoder needs the same code table. Three options:
- Static table (pre-agreed for the data type, e.g., JPEG uses fixed tables)
- Stored in the file header (the tree, or just the frequencies)
- Adaptive (encoder + decoder both update the tree as they go — no need to store)
For this lesson we just emit the bit string (no header, no packing yet). The decoder lessons cover packing.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…