Could anyone help me understand how to insert or write a bit in a byte?
I have a homework where I have to implement Huffman algorithm. I found out the code for each character from the input file and I memorized it in a char matrix code[100][100], where on each line is a code for a character. Now I have to write the output file which contains bits with the code for each character.
So, if I understand, you want to output the variables in base 2 and not base 10 (output bits not numbers)? That's simple enough in this case, actually. I'll give you some pointers:
To see if a bit is turned on, use if(variable & (1 << /*index of bit*/))
Remember, just like base 10, the first digit is digit 0 and is on the rightmost side when written; the first digit in the number 1753210 is 2, just as the first digit in the number 102 (210) is 0.
You will want to read this page: http://www.cplusplus.com/doc/boolean/