Create a program in C++ which checks for 1 bit errors in an error detection system which uses a single parity bit (the single parity bit checks the parity of all bits in each code). Each code is 8 bits (7 bits for data and one for parity). The code distance is 2. You program should check for even parity (parity bit is 1 for even parity). Your program should allow the user to input a single unsinged decimal value up to 255, and then output whether there is a 1 bit error or not.
if the number of 1;s are even then there is no error and if there are odd numbers of 1's there is error
because parity bits are used to maintain even numbers of 1's
C++ code :
int main()
{
int input;
cin>>input;
int cnt=0;
while(input!=0)
{
int r=input%2;
if(r==1)
cnt++;
}
if(cnt%2==1)
cout<<"ERROR OCCURED";
else
cout<<"NO ERROR";
return 0;
}
PLEASE UPVOTE
Get Answers For Free
Most questions answered within 1 hours.