SlideShare ist ein Scribd-Unternehmen logo
1 von 7
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

Probabilistic Reasoning
Probabilistic ReasoningProbabilistic Reasoning
Probabilistic ReasoningJunya Tanaka
 
Predicate logic_2(Artificial Intelligence)
Predicate logic_2(Artificial Intelligence)Predicate logic_2(Artificial Intelligence)
Predicate logic_2(Artificial Intelligence)SHUBHAM KUMAR GUPTA
 
AI 7 | Constraint Satisfaction Problem
AI 7 | Constraint Satisfaction ProblemAI 7 | Constraint Satisfaction Problem
AI 7 | Constraint Satisfaction ProblemMohammad Imam Hossain
 
Deep Reinforcement Learning
Deep Reinforcement LearningDeep Reinforcement Learning
Deep Reinforcement LearningUsman Qayyum
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy methodhodcsencet
 
Lecture9 - Bayesian-Decision-Theory
Lecture9 - Bayesian-Decision-TheoryLecture9 - Bayesian-Decision-Theory
Lecture9 - Bayesian-Decision-TheoryAlbert Orriols-Puig
 
K Means Clustering Algorithm | K Means Clustering Example | Machine Learning ...
K Means Clustering Algorithm | K Means Clustering Example | Machine Learning ...K Means Clustering Algorithm | K Means Clustering Example | Machine Learning ...
K Means Clustering Algorithm | K Means Clustering Example | Machine Learning ...Simplilearn
 
Automata theory -Conversion of ε nfa to nfa
Automata theory -Conversion of ε nfa to nfaAutomata theory -Conversion of ε nfa to nfa
Automata theory -Conversion of ε nfa to nfaAkila Krishnamoorthy
 
Machine Learning - Accuracy and Confusion Matrix
Machine Learning - Accuracy and Confusion MatrixMachine Learning - Accuracy and Confusion Matrix
Machine Learning - Accuracy and Confusion MatrixAndrew Ferlitsch
 
Sequence to sequence (encoder-decoder) learning
Sequence to sequence (encoder-decoder) learningSequence to sequence (encoder-decoder) learning
Sequence to sequence (encoder-decoder) learningRoberto Pereira Silveira
 
2D transformation (Computer Graphics)
2D transformation (Computer Graphics)2D transformation (Computer Graphics)
2D transformation (Computer Graphics)Timbal Mayank
 
Polygon clipping with sutherland hodgeman algorithm and scan line fill algorithm
Polygon clipping with sutherland hodgeman algorithm and scan line fill algorithmPolygon clipping with sutherland hodgeman algorithm and scan line fill algorithm
Polygon clipping with sutherland hodgeman algorithm and scan line fill algorithmMani Kanth
 

Was ist angesagt? (20)

Probabilistic Reasoning
Probabilistic ReasoningProbabilistic Reasoning
Probabilistic Reasoning
 
KNN
KNN KNN
KNN
 
07 approximate inference in bn
07 approximate inference in bn07 approximate inference in bn
07 approximate inference in bn
 
Predicate logic_2(Artificial Intelligence)
Predicate logic_2(Artificial Intelligence)Predicate logic_2(Artificial Intelligence)
Predicate logic_2(Artificial Intelligence)
 
AI 7 | Constraint Satisfaction Problem
AI 7 | Constraint Satisfaction ProblemAI 7 | Constraint Satisfaction Problem
AI 7 | Constraint Satisfaction Problem
 
AI 6 | Adversarial Search
AI 6 | Adversarial SearchAI 6 | Adversarial Search
AI 6 | Adversarial Search
 
Deep Reinforcement Learning
Deep Reinforcement LearningDeep Reinforcement Learning
Deep Reinforcement Learning
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
 
Lecture9 - Bayesian-Decision-Theory
Lecture9 - Bayesian-Decision-TheoryLecture9 - Bayesian-Decision-Theory
Lecture9 - Bayesian-Decision-Theory
 
K - Nearest neighbor ( KNN )
K - Nearest neighbor  ( KNN )K - Nearest neighbor  ( KNN )
K - Nearest neighbor ( KNN )
 
K Means Clustering Algorithm | K Means Clustering Example | Machine Learning ...
K Means Clustering Algorithm | K Means Clustering Example | Machine Learning ...K Means Clustering Algorithm | K Means Clustering Example | Machine Learning ...
K Means Clustering Algorithm | K Means Clustering Example | Machine Learning ...
 
Automata theory -Conversion of ε nfa to nfa
Automata theory -Conversion of ε nfa to nfaAutomata theory -Conversion of ε nfa to nfa
Automata theory -Conversion of ε nfa to nfa
 
Machine Learning - Accuracy and Confusion Matrix
Machine Learning - Accuracy and Confusion MatrixMachine Learning - Accuracy and Confusion Matrix
Machine Learning - Accuracy and Confusion Matrix
 
Sequence to sequence (encoder-decoder) learning
Sequence to sequence (encoder-decoder) learningSequence to sequence (encoder-decoder) learning
Sequence to sequence (encoder-decoder) learning
 
Naive Bayes
Naive BayesNaive Bayes
Naive Bayes
 
2D transformation (Computer Graphics)
2D transformation (Computer Graphics)2D transformation (Computer Graphics)
2D transformation (Computer Graphics)
 
Tsp branch and-bound
Tsp branch and-boundTsp branch and-bound
Tsp branch and-bound
 
K-means and GMM
K-means and GMMK-means and GMM
K-means and GMM
 
Bayesian networks
Bayesian networksBayesian networks
Bayesian networks
 
Polygon clipping with sutherland hodgeman algorithm and scan line fill algorithm
Polygon clipping with sutherland hodgeman algorithm and scan line fill algorithmPolygon clipping with sutherland hodgeman algorithm and scan line fill algorithm
Polygon clipping with sutherland hodgeman algorithm and scan line fill algorithm
 

Andere mochten auch

Andere mochten auch (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
 

Ähnlich wie CRC JAVA CODE

13-DataLink_02.ppt
13-DataLink_02.ppt13-DataLink_02.ppt
13-DataLink_02.pptWinterSnow16
 
第四次课程 Chap8
第四次课程 Chap8第四次课程 Chap8
第四次课程 Chap8Emma2013
 
CRC implementation
CRC implementation CRC implementation
CRC implementation ajay singh
 
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 PPTKrishbathija
 
Reed solomon Encoder and Decoder
Reed solomon Encoder and DecoderReed solomon Encoder and Decoder
Reed solomon Encoder and DecoderAmeer H Ali
 
Cyclic Redundancy Check
Cyclic Redundancy CheckCyclic Redundancy Check
Cyclic Redundancy CheckRajan Shah
 
Convolutional Error Control Coding
Convolutional Error Control CodingConvolutional Error Control Coding
Convolutional Error Control CodingMohammed Abuibaid
 
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)theijes
 
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...IRJET Journal
 
Oth1
Oth1Oth1
Oth1b137
 

Ähnlich wie 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
 
Hamming codes
Hamming codesHamming codes
Hamming codes
 
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
 

Kürzlich hochgeladen

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
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 ConsultingTechSoup
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 

Kürzlich hochgeladen (20)

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).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
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 

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: