class LeFun {

    public static byte calculateCRC(final byte[] buffer, final int length) {
        int result = 0;
        for (int index = 0; index < length; index++) {
            for (int bit = 0; bit < 8; bit++) {
                result = ((buffer[index] >> bit ^ result) & 1) == 0 ? result >> 1 : (result ^ 0x18) >> 1 | 0x80;
            }
        }
        return (byte) result;
    }

}