Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^5: How to use perl digest module to calculate CRC?

by BrowserUk (Pope)
on Mar 21, 2013 at 16:39 UTC ( #1024786=note: print w/ replies, xml ) Need Help??


in reply to Re^4: How to use perl digest module to calculate CRC?
in thread How to use perl digest module to calculate CRC?

However, it seems that there is a problem with this approach. Not all HEX values have a "valid" ascii value that can be sent to the digest::crc. For example: if HEX=01 --> ASCII=SOH, which is not really a char that can be sent. That means that many HEX vals can't be in the game... Am I correct about that?

No. SOH is just a byte with the numeric value 1, and it is a perfectly valid ASCII character. pack will pack it just fine.


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.


Comment on Re^5: How to use perl digest module to calculate CRC?
Re^6: How to use perl digest module to calculate CRC?
by guyra (Novice) on Apr 02, 2013 at 11:17 UTC

    Thanks!

    indeed, the SOH does affect the CRC result.

    #data = (HEX) 3132 my $ctx = Digest::CRC->new(width => 32, poly => 0x04c11db7, init => +0xFFFFFFFF, xorout => 0xFFFFFFFF, refin => 1, refout => 1); my $r = $ctx->add( pack 'H*', '3132' )->hexdigest; print "data=", (pack 'H*', '3132'), "= | r=$r=\n"; #data = (ASCII) 12 my $ctx = Digest::CRC->new(width => 32, poly => 0x04c11db7, init => +0xFFFFFFFF, xorout => 0xFFFFFFFF, refin => 1, refout => 1); my $r = $ctx->add( "12" )->hexdigest; print "data=", (pack 'H*','3132'), "= | r=$r=\n"; #data = (HEX) 310132 my $ctx = Digest::CRC->new(width => 32, poly => 0x04c11db7, init => +0xFFFFFFFF, xorout => 0xFFFFFFFF, refin => 1, refout => 1); my $r = $ctx->add(pack 'H*','310132' )->hexdigest; print "data=", (pack 'H*', '310132'), "= | r=$r=\n";

    Results in:

    data=12= | r=4f5344cd= data=12= | r=4f5344cd= data=12= | r=b243674=

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2015-07-06 00:35 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 (68 votes), past polls