Record DCN (S)
Record DCN (S)
Record DCN (S)
1 Date:
AIM:
To implement Error Detection codes such as Parity Checker code and Cyclic
Redundancy Check Code in C Language.
ALGORITHM:
PARITY CHECKER:
1. Start.
2. Get the data and the divisor as input.
3. Perform XOR division and determine the remainder.
4. Then append the remainder at the end of data bits.
5. Get the received data from the user.
6. Again, perform the XOR division, if the remainder is '0', then the received data bit isnot
corrected.
7. Else the received data bit is corrupted.
8. Stop.
THEORY:
PARITY CHECKER:
Parity checking is the most basic form of error detection in communications. A parity check is a
process that ensures accurate data transmission between nodes duringcommunication. A parity bit is
appended to the original data bits to create an even or odd number, the number of bits to value one. The
source then transmits this data via a link, and bitsare checked and verified at the destination. Data is
considered accurate if the number of bits matches the number transmitted from the source.
//parity code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
int main(){
int i, count =0, tflag, rflag, test;
char data[20];
printf("\nEnter no of bits of data : ");
scanf("%d", &datlen);
printf("\nEnter data : ");
scanf("%s", data);
tflag = check(data);
printf("\nTramsmitted data :\n");
strcpy(rdata,data);
printf(" %s ",rdata);
rdata[0] = (rand()%2 == 0)?'0':'1';
printf("\nthe data : ");
for(i =0;i< datlen; ++i)
printf("%c", rdata[i]);
printf("\nReceived data : %s ", rdata);
rflag = check(rdata);
if(tflag == rflag){
printf("\nThe received message has no error\n");
}
else{
printf("\nThe received message has error !!!\n");
}
return 0;
}
PARITY CHECKER:
Parity checking is the most basic form of error detection in communications. A parity check is a
process that ensures accurate data transmission between nodes duringcommunication. A parity bit is
appended to the original data bits to create an even or odd number, the number of bits to value one. The
source then transmits this data via a link, and bitsare checked and verified at the destination. Data is
considered accurate if the number of bits matches the number transmitted from the source.
Parity checking, which was created to eliminate data communication errors, is a simplemethod of
network data verification and has an easy and understandable working mechanism.
As an example, if original data is 1010001, there are three 1's when even parity checkingis used, a
parity bit with value 1 is added to data left side to make the number of ones even; transmitted data becomes
11010001. However, if odd parity checking is used, then the parity bit value is 0,01010001.
If the original data contains an even number of 1's, then parity bit of value 1 is added to the data's
left side to make the number of ones is odd, if odd parity checking is used and datatransmitted becomes
11101001. In case data is transmitted incorrectly, the parity bit value becomes incorrect, thus indicating
an error has occurred during transmission.
Parity checking is used not only in communication but also to test memory storage devices Many
PCs, for example, perform a parity check on memory every time a byte of data is read.
OUTPUT:
Count : 2
In data transmission, the ability of a receiving station to correct errors in the received data is called
forward error correction (FEC) and can increase throughput on a data link whenthere is a lot of mouse
present. To enable this, the transmitting station must add extra data (called error corrections bits)to the
transmission. However, the correction may not always represent a cost-saving over that of simply resending
the information.
//cyclic redundancy check
#include <stdio.h>
char data[20], divi[20], temp[20], total[100];
int i,j,datalen,divlen,len,flag =1;
void check();
int main(){
printf("\nEnter no of bits of data: ");
scanf("%d",&datalen);
printf("\nEnter no of bits of divisor: ");
scanf("%d",&divlen);
printf("\nEnter data: ");
scanf("%s",data);
printf("\nEnter divisor: ");
scanf("%s",divi);
len = datalen + divlen -1;
for(i =0; i<datalen; i++){
total[i] = data[i];
temp[i] = data[i];}
for(i=datalen; i<len; i++){
total[i] = '0';}
check();
for(i =0; i<divlen; i++){
temp[i+datalen] = data[i]; }
printf("\nTransmitted data : %s",temp);
for(i=0;i<len;++i)
total[i] = temp[i];
srand(time(NULL));
total[3] = (rand()%2==0)?'0':'1';
check();
for(i=0; i<divlen; i++){
if(data[i] == '1')
{flag =0; break;}}
if(flag ==1)
printf("\nSuccess data has no error :)");
else
printf("\nFailure data has some error:(");}
void check(){
for(j =0; j<divlen; j++)
data[j] = total[j];
while(j<=len){
if(data[0] == '1')
for(i=1;i<divlen; i++)
data[i] = ((data[i] == divi[i])?'0':'1');
A cyclic redundancy check (CRC) is an error-detecting code commonly used in digitalnetworks and
storage devices to detect accidental changes to raw data. The CRC was inventedby W. Wesley Peterson in
1961, the 32-bit CRC function of Ethernet and many other standardsis the work of several researchers and
was published in 1975.
CRC is based on binary division. In CRC, instead of adding bits to achieve the desiredparity, a
sequence of redundant bits, called the CRC or CRC remainder, is appended to the endof the data unit so
that the resulting data unit becomes exactly divisible by a second,predetermined binary number. At the
destination, the incoming data unit is assumed to be intactand is therefore accepted. A remainder indicates
that the data unit has been damaged in transitand therefore must be rejected.
OUTPUT:
Enter data:11101
Enter divisor:110
Transmitted data:11101
1110100
Enter data:1010
Enter divisor:101
Transmitted data:10100
data:1101
Thus, the error-detecting codes such as Parity Checker codes and Cyclic RedundancyCheck
Codes has been implemented and verified successfully.
Ex. No. 2 Date:
ALGORITHM:
Hamming Code is a set of error correction code that can be used to detect and correct it error that can
occur when computer data is moved or stored. Hamming code is named R.W Hamming of Bell Labs.
Hamming codes makes FEC less expensive to implement through the use of block parity mechanism.
1. A minimum number of redundancy bits are needed to correct any single bit error in the
data.
2. A minimum number of 4 redundancy bits is needed if the number of data bits is 4.
3. Redundancy bits in the hamming code are placed in the code word bit positions that are
raised to the power of 2.
4. Each redundancy bit is the parity bit for a different combination of data bits.
5. Each data bits may be included in more than one parity check.
//hamming code
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void main(){
int data[7],rec[7],i,c1,c2,c3,c;
data[6] = data[0]^data[2]^data[4];
data[5] = data[0]^data[1]^data[4];
data[3] = data[0]^data[1]^data[2];
printf("\nRand = %d\n",rec[4]);
printf("\nReceived Data : ");
for(i=0;i<7;++i)
printf("%d",rec[i]);
c1 = rec[6]^rec[4]^rec[2]^rec[0];
c2 = rec[5]^rec[4]^rec[1]^rec[0];
c3 = rec[3]^rec[2]^rec[1]^rec[0];
c = c3*4+c2*2+c1;
if(c==0)
printf("\nNO ERROR\n");
else{
printf("\nError position : %d\n",7-c);
printf("\nThe correct message : \n");
rec[7-c] = (rec[7-c] == 0)?1:0;
for(i=0;i<7;++i)
printf("%d",rec[i]);
}
}
Hamming codes detect two-bit errors with more than one parity bit, each of which is computed
on different combinations of bits in the data. The number of parity bits required depends on the number
of bits in the data transmission, and is calculated by the hammingrule. d+p+1<=2(1), where d is the no of
data bits and p is the no of parity bits.
Rand =0
Received Data :
1100001
NO ERROR!!!
Rand =1
Received Data:
1010110
Error position :4