Parity Bit : The parity bit of a sequence of bits is 1 if the number of 1s in sequence is odd, otherwise 0.
Program:
#include <cstdlib> #include <iostream> using namespace std; int main(int argc, char** argv) { int a = 1; int counter1 = 0; while (a) { a = a & (a - 1); counter1 ++ ; } if(counter1 % 2 == 0){ //for even 1s cout << "Parity bit is : 0 "; }else { cout << "Parity bit is : 1 "; } return 0; }