Here you can find the source of calcCheckSum(byte[] bytes, int num)
public static final int calcCheckSum(byte[] bytes, int num)
//package com.java2s; //License from project: Apache License public class Main { public static final int calcCheckSum(byte[] bytes, int num) { return calcCheckSum(bytes, 0, bytes.length, num); }/*from w w w . jav a2 s . c om*/ public static final int calcCheckSum(byte[] bytes, int offset, int length, int num) { int cs = Integer.MAX_VALUE; for (int i = offset; i < length; i += num) { int sum = 0; int loc = 0; for (int n = 0; n < num; n++) { // loc = i + n; if (loc > offset + length || loc >= bytes.length) break; sum += (bytes[i + n] & 0xff); } cs ^= sum; } return cs; } public static final int calcCheckSum(byte[] bytes) { return calcCheckSum(bytes, 1); } }