๐ŸŒ
B.TECH III YEAR โ€ข I SEMESTER โ€ข R22

Computer Networks - Lab Manual

Computer Networks Laboratory โ€ข Program Solution

๐Ÿ“˜ R22 Regulation ๐ŸŽ“ III Year ๐Ÿ“š I Semester ๐ŸŒ Computer Networks ๐Ÿงช Lab Program
Selected Program

Write a program to compute CRC code for the polynomials CRC-12, CRC-16 and CRC-CCITT.

โ† All Computer Networks Programs

CRC :


Source Code:

File Name: crc.c

#include<stdio.h>
int main() {
    int data[100], div[20], temp[100];
    int datalen = 0, divlen = 0, i, j;

    char ch;

    // Input data
    printf("Enter the data (binary): ");
    while ((ch = getchar()) != '\n') {
        if (ch == '1' || ch == '0') {
            data[datalen++] = ch - '0';
        }
    }

    // Input divisor
    printf("Enter the divisor (generator polynomial): ");
    while ((ch = getchar()) != '\n') {
        if (ch == '1' || ch == '0') {
            div[divlen++] = ch - '0';
        }
    }

    // Copy data to temp and append zeros for CRC calculation
    for (i = 0; i < datalen; i++) {
        temp[i] = data[i];
    }
    for (i = 0; i < divlen - 1; i++) {
        temp[datalen + i] = 0;
    }

    int totalLen = datalen + divlen - 1;

    // CRC Division
    for (i = 0; i <= totalLen - divlen; i++) {
        if (temp[i] == 1) {
            for (j = 0; j < divlen; j++) {
                temp[i + j] = temp[i + j] ^ div[j];
            }
        }
    }

    // Append CRC (remainder) to data
    for (i = 0; i < datalen; i++) {
        printf("%d", data[i]);
    }

    printf(" (Data) + ");

    for (i = datalen; i < totalLen; i++) {
        printf("%d", temp[i]);
        data[i] = temp[i]; // Appending CRC bits
    }

    printf(" (CRC)\n");

    // Final transmitted data
    printf("Transmitted Data (Data + CRC): ");
    for (i = 0; i < totalLen; i++) {
        printf("%d", data[i]);
    }
    printf("\n");

    return 0;
}


Output:


$ gcc crc.c
$ ./a.out
Enter the data (binary): 101010111
Enter the divisor (generator polynomial): 1011
101010111 (Data) + 001 (CRC)
Transmitted Data (Data + CRC): 101010111001



๐Ÿ’ป Run This C Program

Write a program to compute CRC code for the polynomials CRC-12, CRC-16 and CRC-CCITT.
The selected C program is loaded automatically into the editor. Edit the program, provide input through STDIN if required and click Run.

The compiler is embedded using OneCompiler. Your C program runs inside the embedded C environment; Study Glance does not execute C code directly on your web server. Enter the input values of the program in the STDIN box before clicking Run.
โ† Back to Computer Networks Lab Programs ๐Ÿ“š All Lab Manuals