0% found this document useful (0 votes)
558 views5 pages

Simulation of Error Detection & Correction Code (CRC, Hamming Code)

The document describes algorithms for implementing CRC and Hamming code for error detection and correction. For CRC, it explains the steps to append redundancy bits, divide the data using a polynomial, transmit and receive the codeword, and check for errors. For Hamming code, it provides steps to calculate redundant bits based on data bit positions, create the codeword, and detect and correct errors at the receiver. Code snippets in Java are given to simulate both algorithms.

Uploaded by

Diksha Nasa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
558 views5 pages

Simulation of Error Detection & Correction Code (CRC, Hamming Code)

The document describes algorithms for implementing CRC and Hamming code for error detection and correction. For CRC, it explains the steps to append redundancy bits, divide the data using a polynomial, transmit and receive the codeword, and check for errors. For Hamming code, it provides steps to calculate redundant bits based on data bit positions, create the codeword, and detect and correct errors at the receiver. Code snippets in Java are given to simulate both algorithms.

Uploaded by

Diksha Nasa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

LAB-4

AIM: Simulation of error detection & correction code (CRC, Hamming


code)
ALGORITHM:
CRC:
1. Open the editor and type the program for error detection
2. Get the input in the form of bits.
3. Append the redundancy bits.
4. Divide the appended data using a divisor polynomial.
5. The resulting data should be transmitted to the receiver.
6. At the receiver the received data is entered.
7. The same process is repeated at the receiver.
8. If the remainder is zero there is no error otherwise there is some error in the
received bits
9. Run the program.

Hamming Code:
Step 1: Start the program.
Step 2: Import net and packages.
Step 3: Get the 7-bit data code
Step 4: Calculation of the number of redundant bits.
Step 5: Positioning the redundant bits.
Step 6: Calculating the values of each redundant bit.
Step 7: Input receiver side data
Step 8: Display error and correct data
CODE:
CRC:
import java.io.*;

class crc
{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Generator:");
String gen = br.readLine();
System.out.println("Enter Data:");
String data = br.readLine();
String code = data;
while(code.length() < (data.length() + gen.length() - 1))
code = code + "0";
code = data + div(code,gen);
System.out.println("The transmitted Code Word is: " + code);
System.out.println("Please enter the received Code Word: ");
String rec = br.readLine();
if(Integer.parseInt(div(rec,gen)) == 0)
System.out.println("The received code word contains no errors.");
else
System.out.println("The received code word contains errors.");
}

static String div(String num1,String num2)


{
int pointer = num2.length();
String result = num1.substring(0, pointer);
String remainder = "";
for(int i = 0; i < num2.length(); i++)
{
if(result.charAt(i) == num2.charAt(i))
remainder += "0";
else
remainder += "1";
}
while(pointer < num1.length())
{
if(remainder.charAt(0) == '0')
{
remainder = remainder.substring(1, remainder.length());
remainder = remainder + String.valueOf(num1.charAt(pointer));
pointer++;
}
result = remainder;
remainder = "";
for(int i = 0; i < num2.length(); i++)
{
if(result.charAt(i) == num2.charAt(i))
remainder += "0";
else
remainder += "1";
}
}
return remainder.substring(1,remainder.length());
}
}

Hamming Code:
import java.util.*;
class HammingCode
{
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter the 7-bit data code”);
int d[]=new int[7];
for(int i=0;i<7;i++)
{
d[i]=sc.nextInt();
}
int p[]=new int[4];
p[0]=d[0]^d[1]^d[3]^d[4]^d[6];
p[1]=d[0]^d[2]^d[3]^d[5]^d[6];
p[2]=d[1]^d[2]^d[3];
p[3]=d[4]^d[5]^d[6];

int c[]=new int[11];


System.out.println(“Complete Code Word is “);

c[0]=p[0];
c[1]=p[1];
c[2]=d[0];
c[3]=p[2];
c[4]=d[1];
c[5]=d[2];
c[6]=d[3];
c[7]=p[3];
c[8]=d[4];
c[9]=d[5];
c[10]=d[6];

for(int i=0; i<11;i++)


{
System.out.print(c[i]+ ” “);
}
System.out.println();
System.out.println(“Enter the Received codeword”);
int r[]=new int[11];
for(int i=0;i<11;i++)
{
r[i]=sc.nextInt();
}

int pr[]=new int[4];


int rd[]=new int[7];

pr[0]=r[0];
pr[1]=r[1];
rd[0]=r[2];
pr[2]=r[3];
rd[1]=r[4];
rd[2]=r[5];
rd[3]=r[6];
pr[3]=r[7];
rd[4]=r[8];
rd[5]=r[9];
rd[6]=r[10];
int s[]=new int[4];
s[0]=pr[0]^rd[0]^rd[1]^rd[3]^rd[4]^rd[6];
s[1]=pr[1]^rd[0]^rd[2]^rd[3]^rd[5]^rd[6];
s[2]=pr[2]^rd[1]^rd[2]^rd[3];
s[3]=pr[3]^rd[4]^rd[5]^rd[6];

int dec=(s[0]*1)+(s[1]*2)+(s[2]*4)+(s[3]*8);
if(dec==0)
System.out.println(“No error”);
else
{
System.out.println(“Error is at “+dec);
if(r[dec-1]==0)
r[dec-1]=1;
else
r[dec-1]=0;
}
System.out.println(“Corrected code word is : “);
for(int i=0;i<11;i++)
System.out.print(r[i]+” “);
System.out.println();
}
}

OUTPUT:
CRC:

Hamming Code:

DIKSHA NASA
RA1911042010003
CSBS-R1

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy