For an assignment, I'm doing a compression/decompression of Huffman algorithm in Visual Studio. After I get the 8 bits (10101010
for example) I want to convert it to a byte. This is the code I have:
unsigned byte = 0;
string stringof8 = "11100011";
for (unsigned b = 0; b != 8; b++){
if (b < stringof8.length())
byte |= (stringof8[b] & 1) << b;
}
outf.put(byte);
First couple of bitstring are output correctly as a byte but then if I have more than 3 bytes being pushed I get the same byte multiple times. I'm not familiar with bit manipulation and was asking for someone to walk me through this or walk through a working function.