java.util.zip.CRC32 uses long??

M

Mohun Biswas

Ok, what am I missing? The primitive type 'long' in Java is defined to
be 64 bits, period, while 'int' is 32. But the getValue() method of the
CRC32 class in java.util.zip returns long! Isn't a CRC32 *guaranteed* to
return 32 bits?

This isn't just academic - it's messing me up a bit because I want to
store a crc32 in the "low" word of a 64-bit quantity and place another
32-bit value in the high word for transmission purposes.

Thanks,
MB
 
M

Marco Schmidt

Mohun Biswas:
Ok, what am I missing? The primitive type 'long' in Java is defined to
be 64 bits, period, while 'int' is 32. But the getValue() method of the
CRC32 class in java.util.zip returns long! Isn't a CRC32 *guaranteed* to
return 32 bits?

CRC32 implements the Checksum interface, which demands long
getValue().
This isn't just academic - it's messing me up a bit because I want to
store a crc32 in the "low" word of a 64-bit quantity and place another
32-bit value in the high word for transmission purposes.

I guess that the upper 32 bits of that resulting long value are always
zero. Check out src.zip to verify that at least Sun's current
implementation does that (I don't want to repost their code here).

Regards,
Marco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top