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

Cyclic Redundancy Check Error-Detecting Technique: Example

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)
52 views5 pages

Cyclic Redundancy Check Error-Detecting Technique: Example

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

CRC stands for Cyclic Redundancy Check.

It is an error-detecting technique commonly used in digital networks and storage devices to


detect accidental changes (errors) in raw data.

Here’s the idea in simple terms:

 Data (message bits) is treated like a large binary number.


 A fixed divisor (called a generator polynomial) is used in binary division.
 The remainder of this division is the CRC value (also called the checksum).
 This CRC value is appended to the original data before transmission or storage.
 At the receiver’s end, the same division is performed:
o If the remainder is 0, the data is assumed to be error-free.
o If not, an error has occurred.

Example:

Suppose we want to send data = 110101


Generator polynomial = 1011

1. Append zeros (based on generator length − 1) → 110101000.


2. Perform binary division (XOR-based).
3. Remainder might be something like 011.
4. Transmit 110101011.
5. Receiver divides again with the same polynomial.
o If remainder = 000, no error detected.
o Otherwise, error detected.

Applications of CRC:

 Ethernet, Wi-Fi, USB data transfer.


 Storage devices (hard drives, CDs, DVDs).
 File compression formats (ZIP, RAR).
 Error detection in embedded systems and communication protocols.

👉 Important: CRC detects errors but does not correct them (unlike error-correcting codes).

Types of CRC’s

CRC — different standards define different generator polynomials and lengths. The type of
CRC mainly depends on:

 The polynomial used


 The length (number of bits) of the CRC

Common types of CRC:

1. CRC-8

 Uses an 8-bit polynomial (e.g., x^8 + x^2 + x + 1 → 100000111 in binary).


 Produces an 8-bit checksum.
 Used in ATM networks, SMBus, automotive applications.

2. CRC-12

 12-bit polynomial.
 Used in telecommunications (Bluetooth, CDMA, etc.).

3. CRC-16

 16-bit polynomial (commonly x^16 + x^15 + x^2 + 1 → 11000000000000101).


 Produces a 16-bit checksum.
 Very popular in USB, Modbus, PPP (Point-to-Point Protocol).

4. CRC-32

 32-bit polynomial (commonly 0x04C11DB7).


 Produces a 32-bit checksum.
 Used in Ethernet, ZIP files, PNG images.

5. CRC-64

 64-bit polynomial.
 Used in some high-reliability storage systems and file systems.

Other specialized CRCs

 CRC-4 → Used in GSM.


 CRC-5 → Used in USB token packets.
 CRC-24 → Used in Bluetooth and OpenPGP.
 CRC-32C (Castagnoli) → Faster, optimized for CPUs (used in iSCSI, SSE 4.2
instructions).

Importance of CRC-16:

 Detects single, double, odd-bit, and burst errors (up to 16 bits).


 Lightweight (only 2 bytes) → fast and efficient for embedded systems.
 Widely used in USB, Modbus, PPP, Bluetooth, industrial automation.
 Provides strong error detection with minimal overhead.
👉 In short: CRC-16 = reliable, efficient, and widely adopted error check for data
communication and storage.

CRC Algorithm

Input:

 Message bits Datastream


 Generator polynomial Generator (degree = r)

Output:

 Transmitted frame (Message + CRC)


 Error detection result

Steps

1. Append Zeros
o Append r zeros (degree of generator) to the message datastream.
o Call this data.
2. Binary Division (Modulo-2)
o Divide data by generator using XOR (no carry).
o Get the remainder R (size r bits).
3. Append CRC
o Append remainder R to original message data.
o This forms the transmitted frame T = data + R.
4. Receiver Side Check
o Receiver divides T by the same generator Generator.
o If remainder = 0 → No error.
o Else → Error detected.

Program

import java.util.Scanner; class CRC{


public static void main(String args[]){
Scanner sc = new Scanner(System.in);
//Input Data Stream
System.out.print("Enter data stream: ");
String datastream = sc.nextLine();
System.out.print("Enter generator: ");
String generator = sc.nextLine();
// assign data[] = length(datastream) + length(generator) - 1
int data[] = new int[datastream.length() + generator.length()-1];
// assign divisor[] = length(generator)
int divisor[] = new int[generator.length()];

for(int i=0;i<datastream.length();i++)
data[i] = Integer.parseInt(datastream.charAt(i)+"");
for(int i=0;i<generator.length();i++)
divisor[i] = Integer.parseInt(generator.charAt(i)+"");
// Perform XOR operation to find remainder
for(int i=0;i<datastream.length();i++){
if(data[i]==1)
for(int j=0;j<divisor.length;j++)
data[i+j] ^= divisor[j];
}
// Find CRC : after XOR operation datastream will be set to zero hence append once again data bits
for(int i=0;i<datastream.length();i++)
data[i] = Integer.parseInt(datastream.charAt(i)+"");
//Display CRC
System.out.print("The CRC code is: ");
for(int i=0;i<data.length;i++)
System.out.print(data[i]);
System.out.println();

//Check for input CRC code


System.out.print("Enter the Recieved Data : ");
datastream = sc.nextLine();

data = new int[datastream.length()+generator.length()-1];

for(int i=0;i<datastream.length();i++)
data[i] = Integer.parseInt(datastream.charAt(i)+"");

//Calculation of remainder
for(int i=0;i<datastream.length();i++){
if(data[i]==1)
for(int j=0;j<divisor.length;j++)
data[i+j] ^= divisor[j];
}
//Display validity of data
boolean valid = true;
for(int i=0;i<data.length;i++)
if(data[i]==1){
valid = false;
break;
}
if(valid==true) System.out.println("Data stream is valid");
else System.out.println("Data stream is invalid. CRC error occured.");
}
}

OUTPUT 1
PS C:\Users\staff_room> java CRC
Enter data stream: 10101
Enter generator: 1011
The CRC code is: 10101101
Enter the Recieved Data : 10101001
Data stream is invalid. CRC error occured.

OUTPUT 2
PS C:\Users\staff_room> java CRC
Enter data stream: 10101
Enter generator: 1011
The CRC code is: 10101101
Enter the Recieved Data : 10101101
Data stream is valid
PS C:\Users\staff_room>

You might also like