cn.t.util.security.message.crc.CrcUtil Maven / Gradle / Ivy
package cn.t.util.security.message.crc;
public class CrcUtil {
public static short crc16Modbus(byte[] inputs) {
int value = 0xFFFF;
for(byte b: inputs) {
for(int i=0; i<8; i++) {
if((((b>>i) ^ value) & 1) == 1) {
value = ((value>>1) ^ 0xA001);
} else {
value>>=1;
}
}
}
return (short)value;
}
}