Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. unsigned short getCRC(char *data_p, unsigned short length) {
  2.     //Prevzate z http://www8.cs.umu.se/~isak/snippets/crc-16.c
  3.     unsigned char i;
  4.     unsigned int data;
  5.     unsigned int crc = 0xffff;
  6.  
  7.     if (length == 0)
  8.         return (~crc);
  9.     do
  10.     {
  11.         for (i = 0, data = (unsigned int)0xff & *data_p++;
  12.             i < 8;
  13.             i++, data >>= 1)
  14.         {
  15.             if ((crc & 0x0001) ^ (data & 0x0001))
  16.                 crc = (crc >> 1) ^ POLY;
  17.             else  crc >>= 1;
  18.         }
  19.     } while (--length);
  20.  
  21.     crc = ~crc;
  22.     data = crc;
  23.     crc = (crc << 8) | (data >> 8 & 0xff);
  24.  
  25.     return (crc);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement