Page 1 of 1

Is this the correct way to create a one byte LRC

Posted: Wed Nov 18, 2009 8:14 pm
by Mike Buckler
Thanks In Advance -
Is this the correct way to create a one byte LRC

Code: Select all

function MyLRC(text)
local ret:=left(text,1),x
    for x = 2 to len(text)
       ret:=chr(nXor( asc(ret), Asc(substr(text,x,1) )   ) )
    next
   return ret

Re: Is this the correct way to create a one byte LRC

Posted: Wed Nov 18, 2009 9:24 pm
by Antonio Linares
Mike,

According to this C code:
http://www.as400pro.com/tipView.php?cat=C&key=8

the right code would be:

Code: Select all

function LRC( cText )

   local nCheckSum := 0
   local n

   for n = 1 to Len( cText )
      nCheckSum = nXor( nCheckSum, Asc( SubStr( cText, n, 1 ) ) )
   next

return nCheckSum
 

Re: Is this the correct way to create a one byte LRC

Posted: Thu Nov 19, 2009 5:16 pm
by Mike Buckler
Thanks Mike