Re: ASTM checksum



In article <11op8o4lcj21055@xxxxxxxxxxxxxxxxxx>, Spin
<cNaOlSePbA@xxxxxxxxxxxxxxxxxx> wrote:

> usenet@xxxxxxxxxxxxxxx wrote:
> > Are the ASTM specs for a cksum different from the "ordinary" POSIX
> > checksum that's been around since the epoch?
> >
> > http://search.cpan.org/~ahamm/String-CRC-Cksum-0.03/Cksum.pm
> >
> No, because the one you linked to gives an integral number whereas the
> ASTM model will return two-digit hexadecimal figures like 7A.

A Cylic Redundancy Checksum (CRC) is quite a different animal from the
simple checksum you described in your original post.

For the string '7L|1|N<CR><ETX>' I get a checksum of 10, or hexadecimal
0x0a, not the 0x40 (=64) that you say you get. How did you arrive at
the value of 0x40?

#!/usr/local/bin/perl

use strict;
use warnings;

my $s = "7L|1|N" . chr(13) . chr(3);
my @c = split(//,$s);
my $chksum = 0;
for my $c ( @c ) {
$chksum = ( $chksum + ord($c) ) % 256;
printf " %3d %4d\n", ord($c), $chksum;
}
printf "checksum = 0x%.2x\n", $chksum;

__OUTPUT__
55 55
76 131
124 255
49 48
124 172
78 250
13 7
3 10
checksum = 0x0a

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
.