Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <iomanip>
- using namespace std;
- int main()
- {
- int m;
- cin>>m;
- int a[7]={0};
- int i=6;
- while(m>0)
- {
- a[i]=m%10;
- m=m/10;
- i--;
- }
- int p1= a[0]^a[2]^a[4]^a[6];
- int p2= a[1]^a[2]^a[5]^a[6];
- int p3= a[3]^a[4]^a[5]^a[6];
- int error_bit= p3*4+p2*2+p1;
- if(error_bit==0)
- {
- cout<<"your code is correct. The number sent is ";
- int number=0;
- number= a[2]*8+a[4]*4+a[5]*2+a[6];
- cout<<number<<endl;
- }
- else
- {
- cout<<"Your code has an error at bit "<<error_bit<<endl;
- cout<<"The corrected code is ";
- if(a[error_bit-1]==0)
- a[error_bit-1]=1;
- else
- a[error_bit-1]=0;
- for(i=0;i<7;i++)cout<<a[i];cout<<endl;
- cout<<"The number sent is ";
- int number=0;
- number= a[2]*8+a[4]*4+a[5]*2+a[6];
- cout<<number<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment