Hi,

I need to implemenmt CRC-32 (with custom poly) in Perl.

I have seen that there is a module called digest::crc that does it.

However, when I compare the result to an online calculator, I dont get the same CRC code.

My poly is "101101" (bin) or "2d" (hex)

My data is "1e5"

The online calc is:

https://ghsi.de/CRC/index.php?Polynom=101101&Message=1e5

The result that I get from the calc is "1010" (bin) or "A" (hex)

This is the perl code I used (found somewhere online...):

use strict; use warnings; use Digest::CRC; my $string = 0x01e5; my $ctx = Digest::CRC->new(type=>"crc32", poly=>0x2D); $ctx->add($string); print "CRC for '$string' is 0x" . $ctx->hexdigest . "\n";

This is the output of this perl:

CRC for '485' is 0x9d0fec86

I'm pretty sure that the online calculator is correct.

Can someone help me understand what is wrong with my Perl code?

Thx!

Guy


In reply to How to use perl digest module to calculate CRC? by guyra

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.