Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Digest::CRC hexdigest not working?

by morphyno (Initiate)
on Dec 20, 2012 at 22:28 UTC ( #1009811=perlquestion: print w/replies, xml ) Need Help??
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 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 (Pope) 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!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1009811]
Approved by GrandFather
and the monastery is silent...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2018-01-21 09:30 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (227 votes). Check out past polls.