Java CRC Calculate crc32(String input)

Here you can find the source of crc32(String input)

Description

crc

License

Open Source License

Declaration

public static String crc32(String input) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String crc32(String input) {
        long CRC = 0xffffffff;
        input = input.toLowerCase();/*from w ww . ja  v a 2  s .c  o m*/
        char[] data = input.toCharArray();
        for (int j = 0; j < data.length; j++) {
            int c = data[j];
            CRC ^= c << 24;
            for (int i = 0; i < 8; i++) {
                if ((CRC & 0x80000000L) != 0) {
                    CRC = (CRC << 1) ^ 0x04C11DB7;
                } else {
                    CRC <<= 1;
                }
            }
        }
        CRC &= 0xffffffffL;

        String r = Long.toString(CRC, 16);
        while (r.length() < 8)
            r = "0".concat(r);
        return r;
    }
}

Related

  1. CRC16_TABLE(byte[] aData, int aSize)
  2. crc32(byte[] array, int offset, int size)
  3. CRC32(final byte[] buf, final int startPos, final int endPos)
  4. crc32(int[] table, int crc, byte[] buffer, int off, int len)
  5. crc32(long crcin, byte[] buf, int off, int alen)
  6. crc320(byte[] buf, int off, int len)
  7. crc321(byte[] buf, int off, int len)
  8. crc32Hash(String key)
  9. crc64(String value)