See the title. The returned value is 32 bits, right? Why not return an int?
The CRC32 checksum sometimes returns negative values. You can use an unsigned shift (x >>> 0) to force JavaScript to treat the arithmetic as unsigned.
All Implemented Interfaces: Checksum. public class CRC32 extends Object implements Checksum. A class that can be used to compute the CRC-32 of a data stream. Passing a null argument to a method in this class will cause a NullPointerException to be thrown.
CRC32 is an error-detecting function that uses a CRC32 algorithm to detect changes between source and target data. The CRC32 function converts a variable-length string into an 8-character string that is a text representation of the hexadecimal value of a 32 bit-binary sequence.
Because if it returned an int, half of the CRC's would be negative. The expectation is that a 32-bit CRC is unsigned, i.e. 0..4294967295, which cannot be represented in an int.
java.util.zip.CRC32
implements the Checksum
interface, which requires a long
return type for getValue()
, therefore requiring a long
for a 32-bit checksum; the upper 32 bits of the output are almost definitely 0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With