@Test public void displayValue() { Object[] crcs = IntStream.range(0, 256) .map(value -> DigestUtil.calculateCrc16(new byte[]{(byte) value})) .mapToObj(Integer::toHexString) .map(s -> StringUtils.leftPad(s, 4, '0')) .toArray(String[]::new); for (int i = 0; i < 32; i++) { String col1 = "" + (i) + '\t' + crcs[i]; String col2 = "" + (i + 32) + '\t' + crcs[i + 32]; String col3 = "" + (i + 64) + '\t' + crcs[i + 64]; String col4 = "" + (i + 96) + '\t' + crcs[i + 96]; String col5 = "" + (i + 128) + '\t' + crcs[i + 128]; String col6 = "" + (i + 160) + '\t' + crcs[i + 160]; String col7 = "" + (i + 192) + '\t' + crcs[i + 192]; String col8 = "" + (i + 224) + '\t' + crcs[i + 224]; System.out.println(col1 + "\t\t" + col2 + "\t\t" + col3 + "\t\t" + col4 + "\t\t" + col5 + "\t\t" + col6 + "\t\t" + col7 + "\t\t" + col8); } }
public static int calculateCrc16(ByteReadable... byteReadables) { if (byteReadables.length == 1) { return calculateCrc16(byteReadables[0].getBytes()); } long currentCrcValue = crc.init(); for (ByteReadable byteReadable : byteReadables) { currentCrcValue = crc.update(currentCrcValue, byteReadable.getBytes()); } short finalCrc = crc.finalCRC16(currentCrcValue); return Short.toUnsignedInt(Short.reverseBytes(finalCrc)); }
DigestUtil { public static int calculateCrc16(ByteReadable... byteReadables) { if (byteReadables.length == 1) { return calculateCrc16(byteReadables[0].getBytes()); } long currentCrcValue = crc.init(); for (ByteReadable byteReadable : byteReadables) { currentCrcValue = crc.update(currentCrcValue, byteReadable.getBytes()); } short finalCrc = crc.finalCRC16(currentCrcValue); return Short.toUnsignedInt(Short.reverseBytes(finalCrc)); } }
DigestUtil { public static int calculateCrc16(ByteReadable... byteReadables) { if (byteReadables.length == 1) { return calculateCrc16(byteReadables[0].getBytes()); } long currentCrcValue = crc.init(); for (ByteReadable byteReadable : byteReadables) { currentCrcValue = crc.update(currentCrcValue, byteReadable.getBytes()); } short finalCrc = crc.finalCRC16(currentCrcValue); return Short.toUnsignedInt(Short.reverseBytes(finalCrc)); } private  DigestUtil(); }
DigestUtil { public static int calculateCrc16(ByteReadable... byteReadables) { if (byteReadables.length == 1) { return calculateCrc16(byteReadables[0].getBytes()); } long currentCrcValue = crc.init(); for (ByteReadable byteReadable : byteReadables) { currentCrcValue = crc.update(currentCrcValue, byteReadable.getBytes()); } short finalCrc = crc.finalCRC16(currentCrcValue); return Short.toUnsignedInt(Short.reverseBytes(finalCrc)); } private  DigestUtil(); static int calculateCrc16(ByteReadable... byteReadables); static int calculateCrc16(byte[] bytes); }
DigestUtil { public static int calculateCrc16(ByteReadable... byteReadables) { if (byteReadables.length == 1) { return calculateCrc16(byteReadables[0].getBytes()); } long currentCrcValue = crc.init(); for (ByteReadable byteReadable : byteReadables) { currentCrcValue = crc.update(currentCrcValue, byteReadable.getBytes()); } short finalCrc = crc.finalCRC16(currentCrcValue); return Short.toUnsignedInt(Short.reverseBytes(finalCrc)); } private  DigestUtil(); static int calculateCrc16(ByteReadable... byteReadables); static int calculateCrc16(byte[] bytes); static final CRC.Parameters CRC16; static final CRC.Parameters CRC16_ADS; }