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?

Replies are listed 'Best First'.
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=