#include #include using namespace std; //Input a series of characters, and output them with even parity added. int main() { for (;;) { char c {'\0'}; //Put 00000000 into c. cin >> c; //Input the next non-whitespace character 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 < 7; ++i) { //Loop through the 7 low bits of c if ((c >> i) & 0x1) { //if bit number i is not 0 ++count; } } if (count % 2 == 1) { //if the count was odd //Turn on bit 7 of c. 0x80 is 10000000 c |= 0x80; //means c = c | 0x80 } cout << c; } return EXIT_SUCCESS; }