Current Forum: Homework 4 - Huffman Trees (Part 1) |
Date: Tue Oct 9 2001 10:43 am |
Author: Maxim, Michael G. <mmaxim@andrew.cmu.edu> |
Subject: Re: little more info about storing bitstrings in ints |
|
|
William,
You can easily store a bitstring in a Vector of ints. Each element of the Vector is an int, either 0 or 1, and you can pass these ints to FileBitWriter.writeBit() which will take the int 0 or 1 and write it to the file as a bit (not as an int or char).
Now keep in mind it does not actually write the bit, it queues up bits in consecutive calls to writeBit() until it has built up 8 bits, and writes those bits as a byte. But you don't have to worry about that until you get to the end of your compressed data and call the final writeBit(). After the final writeBit() make sure to call FileBitWriter.flush() to ensure that all bits are written to the file.
Mike |
|