Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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 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?

Comment on Digest::CRC hexdigest not working?
Select or Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1009811]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (12)
As of 2015-07-29 22:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls