#include #include // Convert a text file of ascii characters // to binary, one byte per line. int main() { fstream fin, fout; char x; unsigned char temp, mask = 0x80; int i, bit; fin.open("c:\\message.txt", ios::in | ios::binary); fout.open("c:\\binary.txt", ios::out); while( (x = fin.get()) != EOF) { for(i = 0; i <= 7; i++) { temp = x & (mask >> i); bit = !(temp == 0); fout << bit << ' '; } fout << endl; } return EXIT_SUCCESS; }