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

Tendances (20)

9. chapter 8 np hard and np complete problems
9. chapter 8   np hard and np complete problems9. chapter 8   np hard and np complete problems
9. chapter 8 np hard and np complete problems
 
Knapsack Problem (DP & GREEDY)
Knapsack Problem (DP & GREEDY)Knapsack Problem (DP & GREEDY)
Knapsack Problem (DP & GREEDY)
 
Time complexity.ppt
Time complexity.pptTime complexity.ppt
Time complexity.ppt
 
Lecture 5 6_7 - divide and conquer and method of solving recurrences
Lecture 5 6_7 - divide and conquer and method of solving recurrencesLecture 5 6_7 - divide and conquer and method of solving recurrences
Lecture 5 6_7 - divide and conquer and method of solving recurrences
 
Dynamic programming - fundamentals review
Dynamic programming - fundamentals reviewDynamic programming - fundamentals review
Dynamic programming - fundamentals review
 
Mini Project final report on " LEAKY BUCKET ALGORITHM "
Mini Project final report on " LEAKY BUCKET ALGORITHM "Mini Project final report on " LEAKY BUCKET ALGORITHM "
Mini Project final report on " LEAKY BUCKET ALGORITHM "
 
Coin Change : Greedy vs Dynamic Programming
Coin Change : Greedy vs Dynamic ProgrammingCoin Change : Greedy vs Dynamic Programming
Coin Change : Greedy vs Dynamic Programming
 
Fundamentals of Computer 20CS11T Chapter 2.pdf
Fundamentals of Computer 20CS11T Chapter 2.pdfFundamentals of Computer 20CS11T Chapter 2.pdf
Fundamentals of Computer 20CS11T Chapter 2.pdf
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Maximum sum subarray
Maximum sum subarrayMaximum sum subarray
Maximum sum subarray
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
NP completeness
NP completenessNP completeness
NP completeness
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic Notation
 
02 order of growth
02 order of growth02 order of growth
02 order of growth
 
Convolutional neural neworks
Convolutional neural neworksConvolutional neural neworks
Convolutional neural neworks
 
Counting sort(Non Comparison Sort)
Counting sort(Non Comparison Sort)Counting sort(Non Comparison Sort)
Counting sort(Non Comparison Sort)
 
Data file handling in python binary & csv files
Data file handling in python binary & csv filesData file handling in python binary & csv files
Data file handling in python binary & csv files
 
Bayesian classification
Bayesian classificationBayesian classification
Bayesian classification
 
Lab report for Prolog program in artificial intelligence.
Lab report for Prolog program in artificial intelligence.Lab report for Prolog program in artificial intelligence.
Lab report for Prolog program in artificial intelligence.
 

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
 
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
 

Dernier

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

Dernier (20)

Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
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
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 

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: