Java Checksum Calculate checksum(byte current, final byte[] data, final int offset, final int length)

Here you can find the source of checksum(byte current, final byte[] data, final int offset, final int length)

Description

Computes a STM32 checksum.

License

Open Source License

Parameter

Parameter Description
current the current checksum value (use 0 to start from scratch)
data the data bytes to check
offset location in data to start computation
length number of bytes to check

Return

the checksum for the specified portion of data

Declaration

public static byte checksum(byte current, final byte[] data,
        final int offset, final int length) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**// w  w w .  ja v  a  2s  .  c o  m
     * Computes a STM32 checksum.
     *
     * @param current the current checksum value (use 0 to start from scratch)
     * @param data the data bytes to check
     * @param offset location in data to start computation
     * @param length number of bytes to check
     * @return the checksum for the specified portion of data
     */
    public static byte checksum(byte current, final byte[] data,
            final int offset, final int length) {
        for (int i = offset; i < offset + length; i++)
            current ^= data[i] & 0xFF;
        return (byte) current;
    }
}

Related

  1. calcChecksum(String value, int length)
  2. calculateChecksum(InputStream is, String algorithm)
  3. calculateChecksums(Optional zos, InputStream inputStream, Set checksumAlgorithms)
  4. checkSum(boolean[] a)
  5. checkSum(byte abyte0[])
  6. checkSum(byte value)
  7. checkSum(byte[] b, int offset, int length)
  8. checksum(byte[] buf, int off, int len)
  9. checksum(byte[] data)