I want to convert a read bit from a binary file to a char so I can add it to a string that would represent a binary format of a file's content. My task is also to read a file byte by byte. I have a following code:
while(f.get(c)){ for(int i=0;i<8;i++){ cout << ((c>>i)&1); //I would like to convert a single bit to a char here } } I cannot figure out how to do it since if I simply add ((c>>i)&1) to string I get a binary form for every bit read so 0 becomes 00000000. Can anyone help me? Thank you in beforehand.