Как рассчитать CRC-16 из значений HEX?

В моем коде мне нужно рассчитать 16-битные значения CRC-16 для значений HEX, хранящихся в виде NSdata, ниже приведен фрагмент кода для вычисления CRC-16 в c.

   void UpdateCRC(unsigned short int *CRC, unsigned char x)
{
  // This function uses the initial CRC value passed in the first
  // argument, then modifies it using the single character passed
  // as the second argument, according to a CRC-16 polynomial
  // Arguments:
  //   CRC -- pointer to starting CRC value
  //   x   -- new character to be processed
  // Returns:
  // The function does not return any values, but updates the variable
  // pointed to by CRC
static int const Poly = 0xA001;
int i;
bool flag;
*CRC ^= x;
for (i=0; i<8; i++)
// CRC-16 polynomial
{
  flag = ((*CRC & 1) == 1);
  *CRC = (unsigned short int)(*CRC >> 1);
  if (flag)
      *CRC ^= Poly;
  }
return; 
}

NSdata, который содержит шестнадцатеричные значения, как показано ниже

const char connectByteArray[] = {
    0x21,0x01,0x90,0x80,0x5F
};
NSData* data = [NSData dataWithBytes: connectByteArray length:sizeof(connectByteArray)];

Ответы на вопрос(1)

Ваш ответ на вопрос