public short CRC(byte[] arr, int len) { int index = 0; // Update the CRC for transmitted and received data using // the CCITT 16bit algorithm (X^16 + X^12 + X^5 + 1). short crc = 0; while (index < len) { crc = (short) ((crc >> 8) | (crc << 8)); crc ^= arr[index++]; crc ^= (char) (crc & 0xff) >> 4; crc ^= (crc << 8) << 4; crc ^= ((crc & 0xff) << 4) << 1; } return crc; }