public class Crcmain {
crc16-1021 type Check,
Crc16-ccitt x16+x12+x5+1 1021 ISO HDLC, ITU x. v.34/v.41/v.42, Ppp-fcs
public static int[] Crc16calc (byte[] data_arr, int data_len)
{
int CRC16 = 0;
int i;
for (i =0; i < (Data_len); i++)
{
CRC16 = (char) ((CRC16 >> 8) | (CRC16 << 8));
CRC16 ^= data_arr[i]& 0xFF;
CRC16 ^= (char) ((CRC16 & 0xFF) >> 4);
CRC16 ^= (char) ((CRC16 << 8) << 4);
CRC16 ^= (char) (((CRC16 & 0xFF) << 4) << 1);
}
int [] result=new int[2];
Result[0]= (crc16/256);
Result[1]= (crc16%256);
return result;
}
public static void Main (string[] args) {
byte[] aa = {0x02, 0x05, 0x00, 0x03, (byte) 0xFF, 0x00,0x00,0x01};
//
Int[] Result=crc16calc (aa,aa.length);
System.out.println (new String (result));
System.out.println (String.Format ("0x%02x", result[0]) + "," +string.format ("0x%02x", result[1]));
}
}
Java CRC (Type 1021, x16+x12+x5+1)