Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Calculate CRC32 checksums with cksum' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Calculate CRC32 checksums with cksum
Authored by: firstianus@yahoo on Dec 28, '04 11:46:54AM

An even simple way of doing it is to use awk instead:

function crc32 { cksum -o3 "$@" | awk '{printf("0x%x\n", $1)}'; }



[ Reply to This | # ]
Calculate CRC32 checksums with cksum
Authored by: fracai on Dec 28, '04 01:45:30PM

doesn't work for me. It looks like it hits an overflow at 2147483647 or 0x7fffffff

does awk have weird ceilings?

---
i am jack's amusing sig file



[ Reply to This | # ]
Calculate CRC32 checksums with cksum
Authored by: guybrush on Dec 28, '04 03:26:48PM

I did use awk first for this purpose but seemed it has a max integer limit at 0x7FFFFFFF, ie 2147483647..

Couldnt find how to solve this problem so I used ruby instead :)



[ Reply to This | # ]
Calculate CRC32 checksums with cksum
Authored by: bdm on Dec 29, '04 05:45:56PM

Within limits you can trick awk past its integer maximum:

cksum -o3 something | awk '{printf("0x%x%02x\n", $1/256,$1%256)}'

If I remember correctly, awk does its arithmetic using doubles.

Brendan.



[ Reply to This | # ]
Calculate CRC32 checksums with cksum
Authored by: bdm on Dec 29, '04 06:58:23PM

Sorry, that should be

... | awk '{printf("0x%x%02x\n", int($1/256),$1%256)}'

to make sure that the truncation to integer is correct.

Brendan.



[ Reply to This | # ]
Calculate CRC32 checksums with cksum
Authored by: LC on Dec 28, '04 08:15:53PM
I usually use bc with obase = 16, for this;
perl ought to be an option too.

[ Reply to This | # ]
Calculate CRC32 checksums with cksum
Authored by: topsnark on Dec 28, '04 08:41:21PM
checkSum+ from http://homepage.mac.com/julifos/soft/checksum/ is a frontend for this and other checksum algorithms. It, too, outputs in hex, using cksum and awk. I'm not sure exactly how, but I think it has avoided such a problem, because I have successfully used it for files large and small.

[ Reply to This | # ]