Jak obliczyć CRC-16 z wartości HEX?

W moim kodzie muszę obliczyć 16-bitowe wartości CRC-16 dla wartości HEX przechowywanych jako NSdata, poniżej znajduje się fragment kodu do obliczenia CRC-16 w 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, która przechowuje wartości heksadecymalne jak poniżej

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

questionAnswers(1)

yourAnswerToTheQuestion