Java Utililty Methods CRC Calculate

List of utility methods to do CRC Calculate

Description

The list of methods to do CRC Calculate are organized into topic(s).

Method

intcalcCRC(final byte[] data)
Calculates the CRC over all config data packets (including the last with the null bytes at the end) (see page 49)
final int POLY = 0x1021;
final int START_VALUE = 0xFFFF;
int crc = START_VALUE;
for (int i = 0; i < data.length; i++) {
    crc = crc ^ ((data[i] & 0xFF) << 8);
    for (int j = 0; j < 8; j++) {
        if ((crc & 0x8000) == 0x8000) {
            crc = crc << 1;
...
intcalcCRC(int crc, byte[] bytes, int start, int len)
calc CRC
initCRCCache();
for (int j = 0; j < len; ++j) {
    final byte b = bytes[j + start];
    crc = calcCRC(crc, b);
return crc;
intcalculateCRC(byte[] buff, int count)
calculate CRC
int crc = 0xFFFF;
int shifts = 0;
int flag = 0x0000;
for (int i = 0; i < buff.length && i < count; i++) {
    crc = (crc & 0xFF00) | ((crc ^ buff[i]) & 0x00FF);
    do {
        flag = crc & 0x0001;
        crc = crc >>> 1;
...
int[]calculateCRC(byte[] data, int offset, int len)
calculate CRC
int[] crc = { 0xFF, 0xFF };
int nextByte = 0;
int uIndex;  
for (int i = offset; i < len && i < data.length; i++) {
    nextByte = 0xFF & ((int) data[i]);
    uIndex = crc[0] ^ nextByte; 
    crc[0] = crc[1] ^ auchCRCHi[uIndex];
    crc[1] = auchCRCLo[uIndex];
...
StringcalculateCRC(String digitsToCheck)
calculate CRC
int sumOdd = 0;
int sumEven = 0;
for (int i = digitsToCheck.length() - 1; i >= 0; i--) {
    char c = digitsToCheck.charAt(i);
    Integer num = Integer.parseInt(Character.toString(c));
    if (isOdd(digitsToCheck.length() - i))
        sumOdd += num;
    else
...
intcalculateCRC(String id)
calculate CRC
if (id == null || id.length() < CRC_WEIGHTS[0].length || !isDigits(id)) {
    return -1;
int crc = CRC_INCORRECT;
int weightPos = 0;
while (crc == CRC_INCORRECT && weightPos < CRC_WEIGHTS.length) {
    crc = 0;
    for (int i = 0; i < ID_LENGTH - 1; i++) {
...
shortcalculateCrc16(byte[] buffer)
calculate Crc
return calculateCrc16(buffer, 0, buffer.length);
intcalculateCRC32(byte[] buf, int off, int len)
Calculates the CRC32 of the given bytes.
int c = 0;
int end = off + len;
for (int i = off; i < end; i++) {
    c = CRC32_TABLE[(c ^ buf[i]) & 0xFF] ^ (c >>> 8);
return c;
longcomputeCRC(InputStream in)
compute CRC
long unitCRC = 0;
BufferedInputStream bufferedInputStream = null;
try {
    bufferedInputStream = new BufferedInputStream(in);
    CheckedInputStream cis = new CheckedInputStream(bufferedInputStream, new Adler32());
    byte[] tempBuf = new byte[128];
    while (cis.read(tempBuf) >= 0) {
    unitCRC = cis.getChecksum().getValue();
} catch (IOException e) {
    return -1;
} finally {
    try {
        bufferedInputStream.close();
    } catch (Exception e) {
return unitCRC;
longcomputeCRC32(File file)
compute CRC
byte buf[] = new byte[32 * 1024];
CRC32 crc = new CRC32();
crc.reset();
FileInputStream fis = null;
try {
    fis = new FileInputStream(file);
    int bytesRead;
    while ((bytesRead = fis.read(buf)) != -1) {
...