Skip to content

Instantly share code, notes, and snippets.

@saisumit
Created November 1, 2016 15:31
Show Gist options
  • Select an option

  • Save saisumit/ea45a876754f0523373b62954aeb4eb2 to your computer and use it in GitHub Desktop.

Select an option

Save saisumit/ea45a876754f0523373b62954aeb4eb2 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for (int i = 0; i < n; i++)
// IMPLEMENT PARITY CHECK
// odd parity error
int main ( )
{
string s ;
cout<<"Enter the received string" << endl ;
cin >> s ;
int n = s.length() ;
vector<int> a( n ) ;
FOR( i , n ) if( s[i] == '0' ) a[i] = 0 ; else a[i] = 1 ;
int pa = 0 ;
FOR( i , n ) pa ^= a[i] ;
if( pa ) cout<<" Error in recieved string " << endl ;
else cout<<" No error " << endl ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment