Blog

CRC32 코드 +1

CRC32 계산

Programing2020. 11. 18. 11:01
반응형
#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;
}
 

Online CRC-8 CRC-16 CRC-32 Calculator

Please enable JavaScript on this site or click one of the buttons above. Share your result: Cookies policies

crccalc.com

반응형