#include <stdio.h>
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;
}
int main () {
unsigned long crc;
char in_frame[12];
in_frame[0] = 0x55;
in_frame[1] = 0xA1;
in_frame[2] = 0x12;
in_frame[3] = 0x34;
in_frame[4] = 0x55;
in_frame[5] = 0xA1;
in_frame[6] = 0x12;
in_frame[7] = 0x34;
in_frame[8] = 0x55;
in_frame[9] = 0xA1;
in_frame[10] = 0x12;
in_frame[11] = 0x34;
crc = crc32b(in_frame);
printf("CRC : %lX", crc);
return 0;
}
CRC On-line 계산기
Post Views: 105