Added functions for bit-packing

Just encode before writing it to file. And decode it the data read from file.