Android Utililty Methods Byte Array Checksum

List of utility methods to do Byte Array Checksum


The list of methods to do Byte Array Checksum are organized into topic(s).


shortcheckSum(byte[] data)
check Sum
long checksum = 0;
for (byte d : data) {
    short element = 0;
    element |= 0x00FF & d;
    checksum += element;
return (short) (checksum & 0xFFFF);
intcheckSum2(byte[] data)
check Sum
long checksum = 0;
int length = data.length;
byte[] temp = new byte[2];
for (int index = 0; index < length - 1; index += 2) {
    temp[0] = data[index];
    temp[1] = data[index + 1];
    int val = bytes2short(temp) & 0x0000FFFF;
    checksum += val;
bytecheckSum(byte[] bytes)
check Sum
byte sum = 0;
for (byte b : bytes) {
    sum ^= b;
return sum;
charcheckSum(byte[] cmdPackage)
Calculates the checksum of a given command package.
char table[] = { 0x0, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5,
        0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c,
        0xd1ad, 0xe1ce, 0xf1ef, 0x1231, 0x210, 0x3273, 0x2252,
        0x52b5, 0x4294, 0x72f7, 0x62d6, 0x9339, 0x8318, 0xb37b,
        0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, 0x2462, 0x3443,
        0x420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, 0xa56a,
        0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
        0x3653, 0x2672, 0x1611, 0x630, 0x76d7, 0x66f6, 0x5695,