bit manipulation - Writing files in bit form to a file in C -


I am implementing the huffman algorithm in C. I've got basic functionality up to that point where binary codards are received. So for example, ABCD 100011000 or something similar will be. Now the question is how do you write this code in binary form in a compressed file. I mean, if I write it normally, then every 1 and 0 will be a letter, so there is no compression.

I have to write those 1s and 0s in their bit form. This is possible in C. If so how?

Collect bits until you have enough bits to fill a byte and then type it ..

Example something like this:

  int current_bit = 0; Unsigned char bit_buffer; FILE * f; Zero WriteBit (int bit) {if (bit) bit_buffer | = (1 & lt; current_bit); Current_bit ++; If (current_bit == 8) {Fillit (and bit_ buffer, 1, 1, f); Current_bit = 0; Bit_buffer = 0; }}  

Once you write your bits, you have to flush the bit-buffer just to do this, just type current_bit equals zero:

 < Code> zero flush_Bits (zero) {while (current_bit) WriteBit (0); }  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -