Hi guys..
In the huffman algorithm I have made an output file contain 0 and 1..
how can I say to compiler that these 1 and zero are bit no Byte.
and how can i make the real Huffman output that its size is lesser than the initial file,
What is the huffman output?
tnx.

Hi guys..
In the huffman algorithm I have made an output file contain 0 and 1..
how can I say to compiler that these 1 and zero are bit no Byte.
and how can i make the real Huffman output that its size is lesser than the initial file,
What is the huffman output?
tnx.

You can't output a single bit. The smallest amount of data that can be written to any storage ( register, cache, ram, HD ) is a byte. If you want to write individual bits, you need to first package them in bytes. So, take your 8 bits, use the left shift operator ( << ) to move the bits to the correct offest, then use a bitwise or ( || ) to combine them into a single byte.

``````char bits[8] = { 1, 1, 0, 0, 1, 1, 0, 1 };
char byte = 0;
for( int i=0; i<8; i++ )
byte = byte | ( bits[i] << i );``````

Don't sweat the "char" type. It's simply an 8 bit integer. Note that the order of bits in the array is "graphically" reversed, so the least significant bit is actually the first item in the array. So, the byte will actually equal the binary value 10110011.

Good luck

Tnx so much for your help,if we change the code in this way :
byte = byte | ( bits << 7-i );
then we protect the order of byte :d

Tnx so much for your help,if we change the code in this way :
byte = byte | ( bits << 7-i );
then we protect the order of byte :d

It depends on byte-ordering. Most modern architectures use a little-endian byte ordering, which means that the least significant bit is on the far right.

``````1 0 0 1 1 0 1
^
|
LSB``````

However, in arrays, we usually think of the element with the lowest order as being on the far left ( at offset 0 )

``````[1, 0, 1, 1, 0, 0, 1]
^
|
Lowest Order Element``````

You should think long and hard about what convention makes the most sense to you. There is no convention that is truly more correct ( though many would fiercely debate that ), however, you should make sure that you use a consistent convention to avoid confusion.

I have another problem in implemention of Huffman code..
in some file there are chararacters that stop the reading of the chars from file if we put flag on default and if we put flag on binary we face a new problem.. in this case for example "Enter" read by get() translate '13' instead of 10 ... what can i do to solve this problem...
tnx

I have another problem in implemention of Huffman code..
in some file there are chararacters that stop the reading of the chars from file if we put flag on default and if we put flag on binary we face a new problem.. in this case for example "Enter" read by get() translate '13' instead of 10 ... what can i do to solve this problem...
tnx

Well, I'm not sure exactly what you are asking here. If you are confused about processing binary files, this website might help you out ( just scroll down to the binary files section). If you post the code that processes the file and its exact output, that would help.

Well, I'm not sure exactly what you are asking here. If you are confused about processing binary files, this website might help you out ( just scroll down to the binary files section). If you post the code that processes the file and its exact output, that would help.