36 lines
837 B
C
36 lines
837 B
C
/*
|
|
* Thanks to echo47
|
|
* http://www.edaboard.com/thread120700.html
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
int main(void)
|
|
{
|
|
unsigned char data[] =
|
|
{
|
|
0xFF, 0xDE, 0xAD, 0xBE, 0xEF, 0x00, 1, 2,3,4,5,6,1,2,0xAA,1,2,3
|
|
};
|
|
unsigned int crc_table[] =
|
|
{
|
|
0x4DBDF21C, 0x500AE278, 0x76D3D2D4, 0x6B64C2B0,
|
|
0x3B61B38C, 0x26D6A3E8, 0x000F9344, 0x1DB88320,
|
|
0xA005713C, 0xBDB26158, 0x9B6B51F4, 0x86DC4190,
|
|
0xD6D930AC, 0xCB6E20C8, 0xEDB71064, 0xF0000000
|
|
};
|
|
unsigned int n, crc=0;
|
|
|
|
for (n=0; n<sizeof(data); n++)
|
|
{
|
|
crc = (crc >> 4) ^ crc_table[(crc ^ (data[n] >> 0)) & 0x0F]; /* lower nibble */
|
|
crc = (crc >> 4) ^ crc_table[(crc ^ (data[n] >> 4)) & 0x0F]; /* upper nibble */
|
|
}
|
|
for (n=0; n<4; n++) /* display the CRC, lower byte first */
|
|
{
|
|
printf("%02X ", crc & 0xFF);
|
|
crc >>= 8;
|
|
}
|
|
printf("\n");
|
|
return 0;
|
|
}
|