Is this the correct way to create a one byte LRC

Post Reply
Mike Buckler
Posts: 67
Joined: Thu Jan 05, 2006 10:35 pm
Location: Canada
Contact:

Is this the correct way to create a one byte LRC

Post 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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

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

Post 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
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
Mike Buckler
Posts: 67
Joined: Thu Jan 05, 2006 10:35 pm
Location: Canada
Contact:

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

Post by Mike Buckler »

Thanks Mike
Post Reply