fork download
  1. #include <stdint.h>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. unsigned char tablica[10] = {3, 54, 21, 0, 0, 0, 0, 0, 10, 247};
  8.  
  9. #define POLY 0x8408 /* 1021H bit reversed */
  10.  
  11.  
  12. unsigned int uiCrc16Cal (unsigned char * buf, uint16_t length) {
  13.  
  14. unsigned char i;
  15. uint16_t data;
  16. uint16_t crc = 0xffff;
  17.  
  18. if (length == 0)
  19. return (~crc);
  20. do
  21. {
  22. for (i=0, data=(uint16_t)0xff & *buf++;
  23. i < 8;
  24. i++, data >>= 1)
  25. {
  26. if ((crc & 0x0001) ^ (data & 0x0001))
  27. crc = (crc >> 1) ^ POLY;
  28. else crc >>= 1;
  29. }
  30. } while (--length);
  31. crc = ~crc;
  32.  
  33. return (crc);
  34. }
  35.  
  36. int main() {
  37. uint16_t crc = uiCrc16Cal(tablica, 8);
  38. cout << (crc & 0x00FF) << " ";
  39. cout << ((crc & 0xFF00) >> 8) << " ";
  40. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
19 209