- May 11, 2008
- 22,105
- 1,382
- 126
Hello. Maybe you can help me what quirks i overlooked.
I am trying to make a crc checksum table generator.
My implementation does not seem to work.
It is almost a straight copy of this example.
To make sure the error is with me, i used the example shown below.
But i get the same results.
All i get is a table filled with zeros.
Why is it not working in visual studio ?
What have i overlooked ?
I am trying to make a crc checksum table generator.
My implementation does not seem to work.
It is almost a straight copy of this example.
To make sure the error is with me, i used the example shown below.
But i get the same results.
All i get is a table filled with zeros.
Why is it not working in visual studio ?
What have i overlooked ?
Code:
// Type definitions.
typedef char int8_t;
typedef unsigned char uint8_t;
typedef short int16_t;
typedef unsigned short uint16_t;
typedef long int32_t;
typedef unsigned long uint32_t;
// Constants.
#define POLYNOMIAL 0x8005
#define MSB_BIT 0x8000 // (1 << 15)
#define INITIAL_REMAINDER 0
// Global variables.
uint16_t g_crctable[256]; // For a 16 bit crc, we need to store 16 bit values.
void CrcTableGenerator(void)
{
uint16_t remainder;
int dividend;
int bit;
/* Compute the remainder of each possible dividend. */
for (dividend = 0; dividend < 256; dividend++)
{
/* Start with the dividend followed by zeros. */
remainder = dividend << 8;
/* Perform modulo-2 division, a bit at a time. */
for (bit = 8; bit > 0; bit--)
{
/* Try to divide the current data bit. */
if (remainder & MSB_BIT)
{
remainder = (remainder << 1) ^ POLYNOMIAL;
}
else
{
remainder = (remainder << 1);
}
}
/* Store the result into the table. */
g_crctable[dividend] = remainder;
}
}