Well anyway...
I think the idea can still work.
Assuming the maximum value for each word is: 65535.
And assuming a packet is maximum of 65535 words then multiple these two
should give the number of carries in the high word
correctly... so no overflows will occur... I checked that yesterday ! ;)
So to be on the safe side the code could be altered a little bit like so:
Carries := Sum shr 16;
Sum := Sum and $FFFF;
while Carries 0 do
begin
Sum := Sum + Carries;
Carries := Sum shr 16;
Sum := Sum and $FFFF;
end;
Or alternatively (probably shorter, less intuitive though):
Carries := 0;
repeat
Sum := Sum + Carries;
Carries := Sum shr 16;
Sum := Sum and $FFFF;
until Carries = 0;
Bye,
Skybuck.
I think the idea can still work.
Assuming the maximum value for each word is: 65535.
And assuming a packet is maximum of 65535 words then multiple these two
should give the number of carries in the high word
correctly... so no overflows will occur... I checked that yesterday ! ;)
So to be on the safe side the code could be altered a little bit like so:
Carries := Sum shr 16;
Sum := Sum and $FFFF;
while Carries 0 do
begin
Sum := Sum + Carries;
Carries := Sum shr 16;
Sum := Sum and $FFFF;
end;
Or alternatively (probably shorter, less intuitive though):
Carries := 0;
repeat
Sum := Sum + Carries;
Carries := Sum shr 16;
Sum := Sum and $FFFF;
until Carries = 0;
Bye,
Skybuck.
Comment