Given a list of symbols sorted by bit-length, the following pseudo code will print a canonical Huffman code book: .
code = 0 while more symbols: print symbol, code code = (code + 1) << ((bit length of the next symbol) - (current bit length)) .