If that function does not work for you, it may be that it needs to use
the first character as a starting point for the xor:
function CalcCheckSum(const S: String):
Word;
var
i: Integer;
begin
if length(s)>0 then
result := word(s[1]);
for i := 2 to Length(S) do
result := result xor Word(S[i]);
end
Cheers,
Nicholas Sherlock
Jeremy Coulter wrote:
Agh...dont you hate that !
Someone shows you a bit of code and you go "oh yeah....DUH !!!"
thanks Phil.
Jeremy
-----Original
Message-----
From: "Phil Middlemiss" <[EMAIL PROTECTED]>
To: "NZ Borland Developers Group - Delphi List"
<[EMAIL PROTECTED]>
Date: Thu, 11 Nov 2004 16:43:50 +1300
Subject: Re: [DUG] 'exclusive or'
here is a simple function I use:
function CalcCheckSum(const S: String): Word;
var
i: Integer;
begin
result := 0;
for i := 1 to Length(S) do
result := result xor Word(S[i]);
end
probably not the fastest, but it's adequate.
Cheers,
Phil.
-----
Original Message -----
Sent:
Thursday, November 11, 2004 4:12 PM
Subject:
[DUG] ’exclusive or’
I am not too good
a this stuff, but I have to pass a checksum at the end of a bit of
data, and the documentation says "the checksum Is calculated by
’exclusive or’ among all sent characters"
How would I do
this?
Jeremy
_______________________________________________
Delphi mailing list
[EMAIL PROTECTED]
http://ns3.123.co.nz/mailman/listinfo/delphi
|
_______________________________________________
Delphi mailing list
[EMAIL PROTECTED]
http://ns3.123.co.nz/mailman/listinfo/delphi