morphyno has asked for the wisdom of the Perl Monks concerning the following question:

I am working to perform CRC32 on some HEX variables. From the website http://www.lammertbies.nl/comm/info/crc-calculation.html CRC32 for 50020301 (input type HEX) is 0xB5E76785 However, when I'm trying to use "hexdigest" apart of Digest::CRC:
my $one = "50020301"; $crc = Digest::CRC->new( type => "crc32" ) ; $crc->add($one); my $out=$crc->hexdigest(); print "The checksum of $one is $out \n";
The checksum of 1342309121 is 7a9735d9 It seems like Digest::CRC is doing ASCII CRC32. I tried setting:
$one = 0x50020301;
But then Digest::CRC interprets that as Dec and converts that to HEX, before continuing ASCII CRC32. Can someone give me some suggestions on how to do HEX CRC32?

Replies are listed 'Best First'.
Re: Digest::CRC hexdigest not working?
by BrowserUk (Patriarch) on Dec 20, 2012 at 23:23 UTC

    You need to pack your ascii-ised hex to binary:

    use Digest::CRC;; $ctx = Digest::CRC->new(type=>"crc32");; print $ctx->add( pack 'H*', '50020301' )->hexdigest;; b5e76785

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    RIP Neil Armstrong

Re: Digest::CRC hexdigest not working?
by morphyno (Initiate) on Dec 21, 2012 at 01:06 UTC
    Thanks! I got it now!