package com.shlb.comb.util; public class CRCutil { /** * 计算CRC16校验码 * * @param bytes * @return */ public static String getCRC(byte[] bytes) { int CRC = 0xFFFF; int POLYNOMIAL = 0xA001; int i, j,m,n; for (i = 0; i < bytes.length; i++) { CRC ^= ((int) bytes[i] & 0x000000ff); for (j = 0; j < 8; j++) { if ((CRC & 0x00000001) != 0) { CRC >>= 1; CRC ^= POLYNOMIAL; } else { CRC >>= 1; } } } m = CRC /256; n = CRC%256; CRC = n * 256 +m; return Integer.toHexString(CRC); } }