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

Still working on getting al the params.

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?

If so, is there any other Perl olution for CRC on HEX data?

Thx

  • Comment on Re^4: How to use perl digest module to calculate CRC?

Replies are listed 'Best First'.
Re^5: How to use perl digest module to calculate CRC?
by BrowserUk (Patriarch) on Mar 21, 2013 at 16:39 UTC
    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.

      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=