code: public static int generate(int crc, char []buffer, int offset, int len)
    {
      for (int i = 0; i < len; i++) {
        char ch = buffer[offset + i];
  
        if (ch > 0xff) {
          crc = next(crc, (ch >> 8));
        }
  
        crc = next(crc, ch);
      }
  
      return crc;
    }
docs: Calculates CRC from a char buffer