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

StringcomputeCrc32(InputStream is)
Compute the CRC-32 of the contents of a stream.
Checksum crc = new CRC32();
int last = -1;
int curr;
while ((curr = is.read()) != -1) {
    if (curr != '\n' && last == '\r') {
        crc.update('\n');
    if (curr != '\r') {
...
StringCRC(String message)
CRC
byte[] bytes = message.getBytes();
int crc = 0x0000;
for (byte b : bytes) {
    crc = (crc >>> 8) ^ table[(crc ^ b) & 0xff];
return Integer.toHexString(crc);
intcrc16(byte[] bytes)
crc
int crc = 0x0000;
for (byte b : bytes) {
    crc = ((crc << 8) ^ LOOKUP_TABLE[((crc >>> 8) ^ (b & 0xFF)) & 0xFF]);
return crc & 0xFFFF;
intcrc16(final byte[] bytes)
crc
int crc = 0xFFFF;
for (int j = 0; j < bytes.length; j++) {
    crc = ((crc >>> 8) | (crc << 8)) & 0xffff;
    crc ^= (bytes[j] & 0xff);
    crc ^= ((crc & 0xff) >> 4);
    crc ^= (crc << 12) & 0xffff;
    crc ^= ((crc & 0xFF) << 5) & 0xffff;
crc &= 0xffff;
return crc;
intcrc16_get(byte aby[], int nOffset, int nLength)
crget
return crc16_get(aby, nOffset, nLength, 0xffff);
shortCRC16_TABLE(byte[] aData, int aSize)
CRTABLE
short nAccum = 0;
for (int i = 0; i < aSize; i++)
    nAccum = (short) ((nAccum << 8) ^ CRC16Table[((nAccum >>> 8) ^ aData[i]) & 0x00FF]);
return nAccum;
intcrc32(byte[] array, int offset, int size)
CRC32 checksum of a byte array range
int crc = 0xFFFF;
for (int pos = offset; pos < offset + size; pos++) {
    crc ^= (int) array[pos];
    for (int i = 8; i != 0; i--) {
        if ((crc & 0x0001) != 0) {
            crc >>= 1;
            crc ^= 0xA001;
        } else {
...
intCRC32(final byte[] buf, final int startPos, final int endPos)
CRC
long c = 0xFFFFFFFFL;
for (int i = startPos; i < endPos; i++) {
    c = (crcTable[(int) ((c ^ buf[i]) & 0xFF)] ^ (c >> 8));
return (int) (c ^ 0xFFFFFFFFL);
intcrc32(int[] table, int crc, byte[] buffer, int off, int len)
This function computes / refreshes a crc32 checksum.
if (table[2] == 0) {
    initCrc32Table(table);
crc = crc ^ 0xffffffff;
for (int n = 0; n < len; n++) {
    crc = table[(crc ^ buffer[n + off]) & 0xff] ^ (crc >>> 8);
return 0xffffffff ^ crc;
...
longcrc32(long crcin, byte[] buf, int off, int alen)
crc
long crc = (crcin & MAXINT_MASK) ^ MAXINT_MASK;
int len = alen;
while (len > 0) {
    crc = _crcTable[((int) crc ^ buf[off++]) & 0xFF] ^ (crc >> 8);
    len--;
final long result = crc ^ MAXINT_MASK;
return result;
...