How to Implement a Checksum Algorithm Based on a Written Description

179 Views Asked by At

I'm working on a project that is asking me to treat data coming from satellites and some frames are ended by a checksum. The ICD lists the checksum as being a "Binary 16-bit sum of data words (2 bytes sum, first byte is MSB), ignoring carry."

From what I understand I made this function in Pascal that takes the length of the frame and the frame itself and returns an unsigned 2 byte integer :

function T_Appli.checksum_calc(tab: array of byte; length: cardinal): word;
var
  checksum : word;
  i : cardinal;
begin
  i := 0;
  checksum := 0;
  while i < length-2 do
  begin
    checksum := checksum xor tab[i] xor (tab[i+1] shl 8);
    i := i+2;
  end;

  if i = length-2 then
    checksum := checksum xor tab[i];

  Result := checksum;
end;

end.

I thought I understood what the description asked me to do... But now I'm not so sure. And finding a good description of the algorithm is surprisingly difficult.

0

There are 0 best solutions below