C语言中的CRC32算法/实现,无查找表且具有公共许可证
我试图用C实现一个CRC32算法,它不使用查找表(我需要在没有足够内存的引导加载程序中使用它)。是否有一个具有公共许可证的可用解决方案?快速搜索。我找不到这些代码片段的许可证 以下各项应能完成这项工作:C语言中的CRC32算法/实现,无查找表且具有公共许可证,c,algorithm,crc32,C,Algorithm,Crc32,我试图用C实现一个CRC32算法,它不使用查找表(我需要在没有足够内存的引导加载程序中使用它)。是否有一个具有公共许可证的可用解决方案?快速搜索。我找不到这些代码片段的许可证 以下各项应能完成这项工作: // ----------------------------- crc32b -------------------------------- /* This is the basic CRC-32 calculation with some optimization but no tabl
// ----------------------------- crc32b --------------------------------
/* This is the basic CRC-32 calculation with some optimization but no
table lookup. The the byte reversal is avoided by shifting the crc reg
right instead of left and by using a reversed 32-bit word to represent
the polynomial.
When compiled to Cyclops with GCC, this function executes in 8 + 72n
instructions, where n is the number of bytes in the input message. It
should be doable in 4 + 61n instructions.
If the inner loop is strung out (approx. 5*8 = 40 instructions),
it would take about 6 + 46n instructions. */
unsigned int crc32b(unsigned char *message) {
int i, j;
unsigned int byte, crc, mask;
i = 0;
crc = 0xFFFFFFFF;
while (message[i] != 0) {
byte = message[i]; // Get next byte.
crc = crc ^ byte;
for (j = 7; j >= 0; j--) { // Do eight times.
mask = -(crc & 1);
crc = (crc >> 1) ^ (0xEDB88320 & mask);
}
i = i + 1;
}
return ~crc;
}
准确地说,您是在寻找算法还是实现?对不起,您完全正确;我更喜欢一个实现,但是一个算法就可以了。