SlideShare une entreprise Scribd logo
1  sur  7
Télécharger pour lire hors ligne
OOSP
PROJECT
Submitted To : Mr. Amol Vasudeva
Submitted By: Sandeep Kumar
101026
X-1(ECE)
JAVA Code: Cyclic Redundancy
Check for Error-Detection
Cyclic Redundancy Check Code for Error- Detection
The Cyclic Redundancy Check (CRC) is a technique for detecting errors in data
transmission, but not for correcting errors when they are detected.
Algorithm:
(A) For Computing CRC :
 The CRC Algorithm is based on polynomial arithmetic.
 Let the message that we have to send has k bits(denoted by M(x) in polynomial
form having degree (k-1) )The sender and the receiver are agreed upon a
generator polynomial having r bits (denoted by G(x) in polynomial form
having degree(r-1) ). The generator polynomial is also called “Divisor”.
 Now, append (r-1) zero bits to the LSB side of the message M(x) so it will now
contain (k+r-1) bits and corresponds to the polynomial x(r-1)
M(x).
 Divide the polynomial x(r-1)
M(x) by Divisor, using modulo-2 subtraction(bit by
bit XOR operation).Add the remainder R(x)(called frame check sequence) to
x(r-1)
M(x), using modulo-2 addition (bit by bit XOR operation). This is the
message that will be transmitted by the transmitter denoted by T(x).
(B) For Error Detection:
 Suppose that a transmission error occurs , so that the received message at the
receiver is T(x)+E(x), instead of T(x).Each 1 bit in E(x) corresponds to a bit that
has been inverted.
 The received message at the receiver end is divided by G(x), i. e. [T(x)+E(x)
/G(x)]. Since T(x) /G(x) is 0, so the result is simply E(x)/G(x).
 If E(x)/G(x)=0 than there is no error in the received message, otherwise there is
an error.
 The following type of errors can be detected using CRC:
 If G(x) has more than one bit and the coefficient of x0
is 1, then all single
bit errors are detected.
 If G(x) is not divisible by x (the coefficient of x0
is 1), and t is the least
positive integer(0<t<n-1) such that G(x) divides xt
+1, then all isolated
double errors are detected.
 If G(x) has a factor (x+1), then all odd numbered errors are detected.
Some standard Generator Polynomials are shown below:
Name Generator Polynomial
CRC-8 x8
+x2
+x+1
CRC-10 x10
+x9
+x5
+x4
+x2
+1
CRC-16 x16
+x12
+x5
+1
CRC-32 x32
+x26
+x23
+x22
+x16
+x12
+x11
+x10
+x8
+x7
+x5
+x4
+x2
+x+1
The following figure illustrates the computation of CRC
CODE:
import java.io.*;
class crc
{
public static void main(String a[]) throws IOException
{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
int[] message;
int[] gen;
int[] app_message;
int[] rem;
int[] trans_message;
int message_bits,gen_bits, total_bits;
System.out.println("n Enter number of bits in message : ");
message_bits=Integer.parseInt(br.readLine());
message=new int[message_bits];
System.out.println("n Enter message bits : ");
for(int i=0; i<message_bits; i++)
message[i]=Integer.parseInt(br.readLine());
System.out.println("n Enter number of bits in gen : ");
gen_bits=Integer.parseInt(br.readLine());
gen=new int[gen_bits];
System.out.println("n Enter gen bits : ");
for(int i=0; i<gen_bits; i++)
{
gen[i]=Integer.parseInt(br.readLine());
}
total_bits=message_bits+gen_bits-1;
app_message=new int[total_bits];
rem=new int[total_bits];
trans_message=new int[total_bits];
for(int i=0;i<message.length;i++)
{
app_message[i]=message[i];
}
System.out.print("n Message bits are : ");
for(int i=0; i< message_bits; i++)
{
System.out.print(message[i]);
}
System.out.print("n Generators bits are : ");
for(int i=0; i< gen_bits; i++)
{
System.out.print(gen[i]);
}
System.out.print("n Appended message is : ");
for(int i=0; i< app_message.length; i++)
{
System.out.print(app_message[i]);
}
for(int j=0; j<app_message.length; j++)
{
rem[j] = app_message[j];
}
rem=computecrc(app_message, gen, rem);
for(int i=0;i<app_message.length;i++)
{
trans_message[i]=(app_message[i]^rem[i]);
}
System.out.println("n Transmitted message from the transmitter is : ");
for(int i=0;i<trans_message.length;i++)
{
System.out.print(trans_message[i]);
}
System.out.println("n Enter received message of "+total_bits+" bits at receiver end : ");
for(int i=0; i<trans_message.length; i++)
{
trans_message[i]=Integer.parseInt(br.readLine());
}
System.out.println("n Received message is :");
for(int i=0; i< trans_message.length; i++)
{
System.out.print(trans_message[i]);
}
for(int j=0; j<trans_message.length; j++)
{
rem[j] = trans_message[j];
}
rem=computecrc(trans_message, gen, rem);
for(int i=0; i< rem.length; i++)
{
if(rem[i]!=0)
{
System.out.println("n There is Error in the received message!!!");
break;
}
if(i==rem.length-1)
{
System.out.println("n There is No Error in the received message!!!");
}
}
static int[] computecrc(int app_message[],int gen[], int rem[])
{
int current=0;
while(true)
{
for(int i=0;i<gen.length;i++)
{
rem[current+i]=(rem[current+i]^gen[i]);
}
while(rem[current]==0 && current!=rem.length-1)
{
current++;
}
if((rem.length-current)<gen.length)
{
break;
}
}
return rem;
}
}
OUTPUT:
CRC JAVA CODE

Contenu connexe

Tendances

Flow & Error Control
Flow & Error ControlFlow & Error Control
Flow & Error Control
tameemyousaf
 

Tendances (20)

Error Detection and correction concepts in Data communication and networks
Error Detection and correction concepts in Data communication and networksError Detection and correction concepts in Data communication and networks
Error Detection and correction concepts in Data communication and networks
 
error control coding
error control coding error control coding
error control coding
 
Presentation bcd adder
Presentation bcd adderPresentation bcd adder
Presentation bcd adder
 
Presentation on cyclic redundancy check (crc)
Presentation on cyclic redundancy check (crc)Presentation on cyclic redundancy check (crc)
Presentation on cyclic redundancy check (crc)
 
Hamming codes
Hamming codesHamming codes
Hamming codes
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
 
Birch Algorithm With Solved Example
Birch Algorithm With Solved ExampleBirch Algorithm With Solved Example
Birch Algorithm With Solved Example
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 
03 Single layer Perception Classifier
03 Single layer Perception Classifier03 Single layer Perception Classifier
03 Single layer Perception Classifier
 
Bcd adder
Bcd adderBcd adder
Bcd adder
 
Bayes Classification
Bayes ClassificationBayes Classification
Bayes Classification
 
Lecture 21
Lecture 21Lecture 21
Lecture 21
 
Tsp branch and-bound
Tsp branch and-boundTsp branch and-bound
Tsp branch and-bound
 
Presentation on bcd adder
Presentation on bcd adderPresentation on bcd adder
Presentation on bcd adder
 
Flow & Error Control
Flow & Error ControlFlow & Error Control
Flow & Error Control
 
Huffman coding
Huffman coding Huffman coding
Huffman coding
 
Np complete
Np completeNp complete
Np complete
 
Cyclic Redundancy Check in Computers Network
Cyclic Redundancy Check in Computers Network Cyclic Redundancy Check in Computers Network
Cyclic Redundancy Check in Computers Network
 
An introduction to Bayesian Statistics using Python
An introduction to Bayesian Statistics using PythonAn introduction to Bayesian Statistics using Python
An introduction to Bayesian Statistics using Python
 
Fuzzy Clustering(C-means, K-means)
Fuzzy Clustering(C-means, K-means)Fuzzy Clustering(C-means, K-means)
Fuzzy Clustering(C-means, K-means)
 

En vedette (6)

CRC Error coding technique
CRC Error coding techniqueCRC Error coding technique
CRC Error coding technique
 
05 directnets errors
05 directnets errors05 directnets errors
05 directnets errors
 
Synthesis
SynthesisSynthesis
Synthesis
 
verilog code
verilog codeverilog code
verilog code
 
CDMA
CDMACDMA
CDMA
 
Cdma ppt for ECE
Cdma ppt for ECECdma ppt for ECE
Cdma ppt for ECE
 

Similaire à CRC JAVA CODE

第四次课程 Chap8
第四次课程 Chap8第四次课程 Chap8
第四次课程 Chap8
Emma2013
 
GROUP03_AMAK:ERROR DETECTION AND CORRECTION PPT
GROUP03_AMAK:ERROR DETECTION AND CORRECTION PPTGROUP03_AMAK:ERROR DETECTION AND CORRECTION PPT
GROUP03_AMAK:ERROR DETECTION AND CORRECTION PPT
Krishbathija
 
Oth1
Oth1Oth1
Oth1
b137
 

Similaire à CRC JAVA CODE (20)

13-DataLink_02.ppt
13-DataLink_02.ppt13-DataLink_02.ppt
13-DataLink_02.ppt
 
Data links
Data links Data links
Data links
 
第四次课程 Chap8
第四次课程 Chap8第四次课程 Chap8
第四次课程 Chap8
 
CRC implementation
CRC implementation CRC implementation
CRC implementation
 
IntrRSCode
IntrRSCodeIntrRSCode
IntrRSCode
 
IntrRSCode
IntrRSCodeIntrRSCode
IntrRSCode
 
IntrRSCode
IntrRSCodeIntrRSCode
IntrRSCode
 
GROUP03_AMAK:ERROR DETECTION AND CORRECTION PPT
GROUP03_AMAK:ERROR DETECTION AND CORRECTION PPTGROUP03_AMAK:ERROR DETECTION AND CORRECTION PPT
GROUP03_AMAK:ERROR DETECTION AND CORRECTION PPT
 
Reed solomon Encoder and Decoder
Reed solomon Encoder and DecoderReed solomon Encoder and Decoder
Reed solomon Encoder and Decoder
 
cyclic_code.pdf
cyclic_code.pdfcyclic_code.pdf
cyclic_code.pdf
 
Cyclic Redundancy Check
Cyclic Redundancy CheckCyclic Redundancy Check
Cyclic Redundancy Check
 
R Language Introduction
R Language IntroductionR Language Introduction
R Language Introduction
 
Convolutional Error Control Coding
Convolutional Error Control CodingConvolutional Error Control Coding
Convolutional Error Control Coding
 
The International Journal of Engineering and Science (The IJES)
The International Journal of Engineering and Science (The IJES)The International Journal of Engineering and Science (The IJES)
The International Journal of Engineering and Science (The IJES)
 
3320 cyclic codes.ppt
3320 cyclic codes.ppt3320 cyclic codes.ppt
3320 cyclic codes.ppt
 
Review paper on Reed Solomon (204,188) Decoder for Digital Video Broadcasting...
Review paper on Reed Solomon (204,188) Decoder for Digital Video Broadcasting...Review paper on Reed Solomon (204,188) Decoder for Digital Video Broadcasting...
Review paper on Reed Solomon (204,188) Decoder for Digital Video Broadcasting...
 
03raster 1
03raster 103raster 1
03raster 1
 
Oth1
Oth1Oth1
Oth1
 
BCH Codes
BCH CodesBCH Codes
BCH Codes
 
Error Control coding
Error Control codingError Control coding
Error Control coding
 

Dernier

Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
MateoGardella
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Dernier (20)

Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 

CRC JAVA CODE

  • 1. OOSP PROJECT Submitted To : Mr. Amol Vasudeva Submitted By: Sandeep Kumar 101026 X-1(ECE) JAVA Code: Cyclic Redundancy Check for Error-Detection
  • 2. Cyclic Redundancy Check Code for Error- Detection The Cyclic Redundancy Check (CRC) is a technique for detecting errors in data transmission, but not for correcting errors when they are detected. Algorithm: (A) For Computing CRC :  The CRC Algorithm is based on polynomial arithmetic.  Let the message that we have to send has k bits(denoted by M(x) in polynomial form having degree (k-1) )The sender and the receiver are agreed upon a generator polynomial having r bits (denoted by G(x) in polynomial form having degree(r-1) ). The generator polynomial is also called “Divisor”.  Now, append (r-1) zero bits to the LSB side of the message M(x) so it will now contain (k+r-1) bits and corresponds to the polynomial x(r-1) M(x).  Divide the polynomial x(r-1) M(x) by Divisor, using modulo-2 subtraction(bit by bit XOR operation).Add the remainder R(x)(called frame check sequence) to x(r-1) M(x), using modulo-2 addition (bit by bit XOR operation). This is the message that will be transmitted by the transmitter denoted by T(x). (B) For Error Detection:  Suppose that a transmission error occurs , so that the received message at the receiver is T(x)+E(x), instead of T(x).Each 1 bit in E(x) corresponds to a bit that has been inverted.  The received message at the receiver end is divided by G(x), i. e. [T(x)+E(x) /G(x)]. Since T(x) /G(x) is 0, so the result is simply E(x)/G(x).  If E(x)/G(x)=0 than there is no error in the received message, otherwise there is an error.  The following type of errors can be detected using CRC:  If G(x) has more than one bit and the coefficient of x0 is 1, then all single bit errors are detected.  If G(x) is not divisible by x (the coefficient of x0 is 1), and t is the least positive integer(0<t<n-1) such that G(x) divides xt +1, then all isolated double errors are detected.  If G(x) has a factor (x+1), then all odd numbered errors are detected.
  • 3. Some standard Generator Polynomials are shown below: Name Generator Polynomial CRC-8 x8 +x2 +x+1 CRC-10 x10 +x9 +x5 +x4 +x2 +1 CRC-16 x16 +x12 +x5 +1 CRC-32 x32 +x26 +x23 +x22 +x16 +x12 +x11 +x10 +x8 +x7 +x5 +x4 +x2 +x+1 The following figure illustrates the computation of CRC
  • 4. CODE: import java.io.*; class crc { public static void main(String a[]) throws IOException { InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); int[] message; int[] gen; int[] app_message; int[] rem; int[] trans_message; int message_bits,gen_bits, total_bits; System.out.println("n Enter number of bits in message : "); message_bits=Integer.parseInt(br.readLine()); message=new int[message_bits]; System.out.println("n Enter message bits : "); for(int i=0; i<message_bits; i++) message[i]=Integer.parseInt(br.readLine()); System.out.println("n Enter number of bits in gen : "); gen_bits=Integer.parseInt(br.readLine()); gen=new int[gen_bits]; System.out.println("n Enter gen bits : "); for(int i=0; i<gen_bits; i++) { gen[i]=Integer.parseInt(br.readLine()); } total_bits=message_bits+gen_bits-1; app_message=new int[total_bits]; rem=new int[total_bits]; trans_message=new int[total_bits]; for(int i=0;i<message.length;i++) { app_message[i]=message[i]; } System.out.print("n Message bits are : "); for(int i=0; i< message_bits; i++) { System.out.print(message[i]); }
  • 5. System.out.print("n Generators bits are : "); for(int i=0; i< gen_bits; i++) { System.out.print(gen[i]); } System.out.print("n Appended message is : "); for(int i=0; i< app_message.length; i++) { System.out.print(app_message[i]); } for(int j=0; j<app_message.length; j++) { rem[j] = app_message[j]; } rem=computecrc(app_message, gen, rem); for(int i=0;i<app_message.length;i++) { trans_message[i]=(app_message[i]^rem[i]); } System.out.println("n Transmitted message from the transmitter is : "); for(int i=0;i<trans_message.length;i++) { System.out.print(trans_message[i]); } System.out.println("n Enter received message of "+total_bits+" bits at receiver end : "); for(int i=0; i<trans_message.length; i++) { trans_message[i]=Integer.parseInt(br.readLine()); } System.out.println("n Received message is :"); for(int i=0; i< trans_message.length; i++) { System.out.print(trans_message[i]); } for(int j=0; j<trans_message.length; j++) { rem[j] = trans_message[j]; } rem=computecrc(trans_message, gen, rem); for(int i=0; i< rem.length; i++) { if(rem[i]!=0)
  • 6. { System.out.println("n There is Error in the received message!!!"); break; } if(i==rem.length-1) { System.out.println("n There is No Error in the received message!!!"); } } static int[] computecrc(int app_message[],int gen[], int rem[]) { int current=0; while(true) { for(int i=0;i<gen.length;i++) { rem[current+i]=(rem[current+i]^gen[i]); } while(rem[current]==0 && current!=rem.length-1) { current++; } if((rem.length-current)<gen.length) { break; } } return rem; } } OUTPUT: