On Fri, Apr 13, 2012 at 01:54:37PM -0700, Kevin O wrote:
> 2-digit checksum: This is the hexadecimal two’s complement of the 
> > modulo-256 sum of

Well, you forgot to make it two's complement.
 
> Any ideas on how to implement this? I've tried the function below but it 
> produces the wrong output.
> 
> function calcChecksum(asciiString) {
>   var buf = new Buffer(asciiString);
>   var sum = 0;
>   for(var i=0; i<buf.length; i++) {
>     sum = sum + buf[i];
>   }
>   sum = sum%256;

Here, insert `sum = sum ^ 0xff`. That should work, I think.

>   return sum.toString(16);
> } 

Attachment: pgp4NCFP3W3ur.pgp
Description: PGP signature

Reply via email to