Discussion Board
Go to the previous messageGo to the following message
Current Forum: Homework 4 - Huffman Trees (Part 1)
Date: Tue Oct 9 2001 12:38 am
Author: Bortz, Andrew S. <abortz@andrew.cmu.edu>
Subject: Re: little more info about storing bitstrings in ints

You can't really. Remember, an int stores a (32-bit in Java?) value, and doesn't store anything else. A 'bitstring' is really a value and a length. You could represent it as a struct from C, or a small class with public variables in Java. Think of a bitstring as what you need to pass to FileBitWriter in order to get it write it, and the solution becomes apparent quickly.

For example, an int with 56 in it could be represented by any number of bitstrings, since we don't know how many bits are used to store it. It could be necessary to store it in 8 bits, or 9, or 10, etc etc.

You shouldn't have to bother with the 'bit-pushing' operations found in FileBitWriter. Just use the writeBits() method and you should be good.

On a side note, if you have some guarantee that the top 5 bits of an int will never be used for data, you could pack the length of a bitstring in the top 5 bits, but that probably won't work for what you want.
Post response

Go to the previous messageGo to the following message
Current Thread Detail:
little more info about storing bitstri...      Liu, William Y.      Tue Oct 9 2001 12:10 am       
Re: little more info about storing ...      Bortz, Andrew S.      Tue Oct 9 2001 12:38 am       
Re: little more info about storing ...      Maxim, Michael G.      Tue Oct 9 2001 10:43 am       
Comp. and DeComp. Speed issues      Yin, Hongxi      Wed Oct 10 2001 1:45 am       
Re: Comp. and DeComp. Speed i...      Maxim, Michael G.      Wed Oct 10 2001 4:25 pm       
Re: Comp. and DeComp. Speed i...      Lee, Charles C.      Wed Oct 10 2001 5:03 pm       
Re: Comp. and DeComp. Spee...      Cipriani, Jason A.      Thu Oct 11 2001 11:07 am       
Re: Comp. and DeComp. S...      Lee, Charles C.      Thu Oct 11 2001 3:17 pm       
Re: Comp. and DeComp...      Cipriani, Jason A.      Fri Oct 12 2001 1:51 am       

Back to previous screen