Immer die CRC-Prüfsumme von byte-array und hinzufügen, um das byte-array

Habe ich dieses byte array:

static byte[] buf = new byte[] { (byte) 0x01, (byte) 0x04, (byte)0x00, (byte)0x01,(byte)0x00, (byte) 0x01};

Nun, die CRC-Checksumme dieses byte-array sein soll, 0x60 0x0A. Ich möchte den Java-code neu dieses Prüfsumme, aber ich kann nicht scheinen, um es neu erstellen. Ich habe versucht crc16:

static int crc16(final byte[] buffer) {
    int crc = 0xFFFF;

    for (int j = 0; j < buffer.length ; j++) {
        crc = ((crc  >>> 8) | (crc  << 8) )& 0xffff;
        crc ^= (buffer[j] & 0xff);//byte to int, trunc sign
        crc ^= ((crc & 0xff) >> 4);
        crc ^= (crc << 12) & 0xffff;
        crc ^= ((crc & 0xFF) << 5) & 0xffff;
    }
    crc &= 0xffff;
    return crc;

}

und konvertieren Sie Sie mithilfe von Integer.toHexString(), aber keines der Ergebnisse mit den richtigen CRC. Könnte jemand bitte zeigen Sie mich in die richtige Richtung in Bezug auf die CRC-Formel.

InformationsquelleAutor GreenGodot | 2013-07-04
Schreibe einen Kommentar