I am writing a code to calculate a CRC16 using 32 bit unsigned integers. When trying to print the return value out from the XOR function that performs the CRC operation it always prints 0. I've tried a variety of debug methods such as print statements, however, I can't seem to figure it out!
Here's my XOR function:
uint32_t XOR(uint32_t divisor, uint32_t dividend)
{
uint32_t divRemainder = dividend;
uint32_t currentBit;
for(currentBit = 32; currentBit > 0; --currentBit)
{
if(dividend && 0x32)
{
divRemainder = divRemainder ^ divisor;
}
divRemainder = divRemainder << 1;
}
return (divRemainder >> 8);
}
The function that calls the above method:
void crcCalculation(char *text, FILE *input, char *POLYNOMIAL)
{
int i = strlen(text);
uint32_t dividend = atoi(POLYNOMIAL);
uint32_t result;
readInput(text, input);
printText(text);
printf("CRC 16 calculation progress:\n");
if(i < 504)
{
for(; i!=504; i++)
{
text[i] = '.';
}
}
result = XOR((uintptr_t)POLYNOMIAL, dividend);
printf(" - %d", result);
}
The constant polynomial (I hope I calculated this correctly for CRC 16:
#define POLYNOMIAL A053
I'd appreciate a nudge in the correct direction!
POLYNOMIALis pointing to, but of the pointer itself. That doesn't seem very useful. You also don't calculate any checksum for thetextstring (which might not be zero-terminated). And do you really define that macro? In combination with the code you show it doesn't make much sense either. - Some programmer dude