Java Checksum Calculate calcCheckSum(byte[] bytes, int num)

Here you can find the source of calcCheckSum(byte[] bytes, int num)

Description

calc Check Sum

License

Apache License

Declaration

public static final int calcCheckSum(byte[] bytes, int num) 

Method Source Code

//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);
    }
}

Related

  1. calcChecksum(byte[] buffer, int offset, int length)
  2. calcChecksum(byte[] buffer, int start, int end)
  3. calcCheckSum(byte[] data, int offset, int maxIdx)
  4. calcChecksum(String value, int length)
  5. calculateChecksum(InputStream is, String algorithm)
  6. calculateChecksums(Optional zos, InputStream inputStream, Set checksumAlgorithms)