#include #include using namespace std; //Input a series of characters, make sure that each one has even parity, //and output them without the parity bit. int main() { for (int n {1};; ++n) { char c {'\0'}; //Put 00000000 into c. cin >> c; if (!cin) { break; //Assume the input failed because we reached } //end of input int count {0}; //count how many of the bits of c are 1's for (int i {0}; i < 8; ++i) { //Loop through the 8 bits of c. if ((c >> i) & 0x1) { //if bit number i is 1 ++count; } } if (count % 2 == 1) { //if count is odd cerr << "\n"; cerr << "Byte number " << n << " had odd parity.\n"; return EXIT_FAILURE; } //Turn off bit 7 of c. 0x7F is 01111111 c &= 0x7F; //means c = c & 0x7F; cout << c; } return EXIT_SUCCESS; }