Ok, I did not know that there exist different versions of how to compute a CRC32. But unfortunately I need this specific one.

Thank you very much for the hint with the Math::BigInt. Now I could get rid of the warnings.

Here the new code:

#!/usr/bin/perl use strict; use warnings; use Math::BigInt; # solution: 990644297 my $buffer = "/etc/test2.sh"; my $crc = Math::BigInt->new('0'); &determineCrc32($buffer, $crc); print $crc . "\n"; sub determineCrc32() { my $buffer = $_[0]; my $crc = $_[1]; my $i = 0; my $val = 0; my $k = 0; for( $i = 0; $i < int(length($buffer) / 4); $i = $i + 1 ) { $val = sprintf("%02X", ord(substr($buffer, ($i*4) + 0, 1))) . sprintf("%02X", ord(substr($buffer, ($i*4) + 1, 1))) . sprintf("%02X", ord(substr($buffer, ($i*4) + 2, 1))) . sprintf("%02X", ord(substr($buffer, ($i*4) + 3, 1))); $crc->badd(hex($val)); $crc->bmod('0x100000000'); } $val = ""; $k = 0; for( 1 .. int(length($buffer) % 4) ) { $val .= sprintf("%02X", ord(substr($buffer, ($i*4) + $k, 1))); $k++; } # pad other bytes of 32bit with "00" for( 1 .. (4 - int(length($buffer) % 4)) ) { $val .= "00"; } $crc->badd(hex($val)); $crc->bmod('0x100000000'); }

Would be very interesting for me how a good perl programmer would code this specific CRC. Because I don't think that my solution is a good way to solve it.

Greetings

Dirk

In reply to Re^4: CRC of a string by Dirk80
in thread CRC of a string by Dirk80

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.