Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Generating a CRC-16/XMODEM checksum in Hex

by Djinni (Novice)
on Feb 20, 2020 at 18:08 UTC ( #11113270=note: print w/replies, xml ) Need Help??


in reply to Generating a CRC-16/XMODEM checksum in Hex

As is so often the case with these things. Mearly asking for help (not even getting any) is sometimes sufficient to help one see the solution!
#!/usr/bin/perl -w use strict; use Digest::CRC; my @s=( { 's'=>"9848C503738276ADCA02BF5DC1A3ABF2", 'crc16'=>"9F4B" }, { 's'=>"841374844ADDF4A36CEDB127C82086B9", 'crc16'=>"408E" }, { 's'=>"8AC1070ACD1659BB4F507191E33F7AD4", 'crc16'=>"E1E3" }, { 's'=>"34623A01DCDA35BED462953B4E2458DA", 'crc16'=>"7B40" }, { 's'=>"E29107CB32975E859D76A885BF57BE35", 'crc16'=>"2B92" }, { 's'=>"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 'crc16'=>"0041" }, ); my $ctx = Digest::CRC->new(type=>"crc16"); $ctx = Digest::CRC->new(width=>16, init=>0x0000, xorout=>0x0000, refout=>0, poly=>0x1021, refin=>0, cont=>0); for my $tv (@s) { my $key = $tv->{s}; my $value = pack "H*", "$key"; $ctx->add($value); my $digest = $ctx->digest; my $hexdigest = sprintf("%X", $digest); print qq{ Input was: $key crc: $digest as HEX: $hexdigest -- Should be: $tv->{crc16} }; }
$hexdigest now has the expected data value!

Replies are listed 'Best First'.
Re^2: Generating a CRC-16/XMODEM checksum in Hex
by stevieb (Canon) on Feb 20, 2020 at 18:28 UTC
    "As is so often the case with these things. Mearly asking for help (not even getting any) is sometimes sufficient to help one see the solution!"

    That's called Rubber Duck Debugging :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2020-06-06 13:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (41 votes). Check out past polls.

    Notices?