Which CRC-32 algorithm is used in the Java CRC-32 class ? The java doc does not give any details. What is the polynomail used and the initial value for calculaton ?
4 Answers
CRC-32 is a indicated in the package docs for java.util.zip to be specified in RFC 1952. RFC 1952 defines CRC32 as specified in ISO 3309 which I could not find a free copy of to link you to. However RFC 1952 also indicates that section 8.1.1.6.2 of ITU-T recommendation V.42 specifies the same implementation.
In partcular the polynomial being used is
x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1
-
I generate the CRC32 using Java class, but I need to explain the algorithm used to the receiver who is not using java. Will I be correct if I give him the following details ? ISO/IEC 3309 compliant 32 bit CRC algorithm Polynomial used is 0x04C11DB7 Initial value would be 0 – Dunxton Jan 25 '12 at 16:22
According to the source:
Computes CRC32 data checksum of a data stream. The actual CRC32 algorithm is described in RFC 1952 (GZIP file format specification version 4.3). Can be used to get the CRC32 over a stream if used with checked input/output streams.
The RFC1952 can be found here, but presents a quite technical read.
The initial value for the CRC is 0xFFFFFFFF
, and the CRC table is built the first time the class is loaded on the VM.

- 4,580
- 7
- 29
- 46
-
1[link](http://regregex.bbcmicro.net/crc-catalogue.htm) says Init value is 0xFFFFFFFF. Im confused ! – Dunxton Jan 25 '12 at 15:13
-
Dunxton, if you initialize a new `CRC32` object with no content and call `getValue()`, it will return `0 & 0xffffffffL` which equals `0`. Not sure if that's what OP meant? – Marcelo Jan 25 '12 at 15:46
-
1I tried this [link](http://www.zorc.breitbandkatze.de/crc.html). For the polynomial 0x04C11DB7 I enter initial value as 0 but the result is not correct. When I try 0XFFFFFFFF I get the expected value. – Dunxton Jan 25 '12 at 16:18
Using some tools from Internet ( http://www.sunshine2k.de/coding/javascript/crc/crc_js.html ) I've found a combination of CRC32 parameters that gives the same results as obtained from Java:
- Input reflected, result reflected.
- Polynomial: 0x04C11DB7.
- Initial value: 0xFFFFFFFF.
- Final XOR: 0xFFFFFFFF

- 832
- 2
- 9
- 26
The currently accepted answer is incorrect.
The initial value for Java's CRC32 class is 0, not 0xFFFFFFFF, as can be seen in the source code for the reset function:
/**
* Resets CRC-32 to initial value.
*/
public void reset() {
crc = 0;
}
I did a quick brute-force search, and it turns out that updating the CRC with the value 0xFFFFFFFF
will actually yield that same value. So if you'd like the CRC32 algorithm to have the initial value 0XFFFFFFFF
, just do:
CRC32 crc = new CRC32();
// Set the initial value to 0xFFFFFFFF
crc.update(new byte[]{(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF});
System.out.println("CRC: " + crc.getValue()); // prints 4294967295, which is 0xFFFFFFFF

- 1
- 1

- 4,825
- 4
- 28
- 23
-
What you are looking at is an implementation detail. CRC32 is defined to output the ones complement. Therefore, `new CRC32().getValue() == 0` is the expected result for an initial value of `0xFFFFFFFF` (since `~0xFFFFFFFF == 0`). The implementation probably just takes the shortcut to calculate everything in the ones complement already, so the output doesn't have to do anything. That's also why `reset()` sets `crc = 0` and not `crc = 0xFFFFFFFF`. – Michi Sep 14 '21 at 13:25