0% found this document useful (0 votes)
3 views2 pages

PRACTICAL 11

The document contains a C program that calculates the CRC-16-ANSI checksum for a given data string. It compares the calculated CRC of the original data with that of received data to detect errors. The output indicates that an error was detected in the received data based on the differing CRC values.

Uploaded by

meghanathani16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

PRACTICAL 11

The document contains a C program that calculates the CRC-16-ANSI checksum for a given data string. It compares the calculated CRC of the original data with that of received data to detect errors. The output indicates that an error was detected in the received data based on the differing CRC values.

Uploaded by

meghanathani16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

PRACTICAL 11

#include <stdio.h>

#include <string.h>

#define POLYNOMIAL 0x11d // CRC-16-ANSI (x^16 + x^15 + x^2 + 1)

unsigned int calculate_crc(unsigned char *data, int length) {

unsigned int crc = 0xFFFF;

for (int i = 0; i < length; i++) {

crc ^= data[i] << 8;

for (int j = 8; j > 0; j--) {

if (crc & 0x8000) {

crc = (crc << 1) ^ POLYNOMIAL;

} else {

crc <<= 1;

return crc;

int main() {

unsigned char data[] = "12346789";

int length = strlen((char*)data);


PRACTICAL 11

unsigned int crc = calculate_crc(data, length);

printf("Calculated CRC: %04X\n", crc);

unsigned char received_data[] = "12356789";

int received_length = strlen((char*)received_data);

unsigned int received_crc = calculate_crc(received_data, received_length);

printf("Received CRC: %04X\n", received_crc);

if (crc == received_crc) {

printf("No error detected.\n");

} else {

printf("Error detected in the received data.\n");

return 0;

OUT OUT:-

Calculated CRC: 69FFE10B

Received CRC: 69B3AAD7

Error detected in the received data.

You might also like