Имеем от производителя прибора функцию по подсчету CRC24 посылки прибору
Код:
function crc_octets (octets: PChar; len: Integer): Integer;
const
CRC24_INIT = $00b704ce;
CRC24_POLY = $01864cfb;
var
crc: Integer;
temp: Integer;
i: Integer;
begin
crc := CRC24_INIT;
while (len <> 0) do
begin
Dec(len);
temp := Integer (octets^);
Inc(octets);
temp := temp shl 16;
crc := crc xor temp;
for i := 0 to 7 do
begin
crc := crc shl 1;
if (crc and $01000000) <> 0 then
crc := crc xor CRC24_POLY;
end;
end;
crc := crc and $00ffffff;
result := crc;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit2.Text := IntToHex(crc_octets(Addr(Edit1.Text[1]), 10), 6);
end;
При вводе в Edit1 строки ffff012001 вмето 452E2B получаем BC5DD3.
Что я делаю не так?
Админ: Пользуемся тегами при оформлении кода!