Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use the provided CRC generator program as a starting point to develop a CRC checking function with the following declaration: unsigned int check_crc(unsigned int g,

Use the provided CRC generator program as a starting point to develop a CRC checking function with the following declaration:

unsigned int check_crc(unsigned int g, unsigned int r) { // g: generator value, r: received word, possibly containing errors to be detected

// The function returns an unsigned int, zero if no error detected, and a value greater than zero otherwise

// Add function code here

}

Submit the C code for this function. The code must compile and run without errors.

/* CRC generator -------------

Uses long-hand division to generate codewords at most 32 bits long using data in hexadecimal format read from standard input. */

#include #include

/* Finds position of most significant 'one' of x (starting count from 1) */ unsigned int find_msop(unsigned int x) { unsigned int position = 0; while (x) { position++; x >>= 1; } return position; }

/* Returns codeword given generator ploynomial (g) and data bits (i) */ unsigned int add_crc(unsigned int g, unsigned int i) { /* registers: must be at least 32 bits long */ unsigned int d, mask; /* regular counters and auxiliary variables */ unsigned int ncrc, j;

ncrc = find_msop(g) - 1; /* Must count from 0 */ d = i << ncrc;

/* Perform long-hand division (but quotient not calculated) */ j = find_msop(d); /* j: index of MSB in d */ while (j > ncrc) { j--; mask = 1 << j; if (d & mask) /* Here we would add a '1' to quotient, else would be a '0' */ d = d ^ (g << (j-ncrc)); }

return (i << ncrc) + d; }

int main() { unsigned int i, g, b; /* Generator polynomial */ g = 0x107; // CRC-8-CCITT

/* read information bits and encode until end of file: data may not have more than 3 bytes or else code fails. Max data 0xffffff */ while (scanf("%x", &i) != EOF) { printf("info = 0x%x", i); b = add_crc(g, i); printf("\t codeword = 0x%x ", b); } return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions

Question

Explain the key areas in which service employees need training.

Answered: 1 week ago

Question

Understand the role of internal marketing and communications.

Answered: 1 week ago