All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.t.util.security.message.crc.CrcUtil Maven / Gradle / Ivy

There is a newer version: 1.0.16.RELEASE
Show newest version
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;
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy