Here you can find the source of checksum(byte current, final byte[] data, final int offset, final int length)
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 |
public static byte checksum(byte current, final byte[] data, final int offset, final int length)
//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; } }