CRC Stream

CrcCCITT

uli
 
Avatar
 
Subject:

CRC Stream

 · 
Posted: 08.01.2011 - 13:33  ·  #1
Hi,

sorry I posted this first in the wrong forum (software)

maybe somebody can give me an hint what I'm doing wrong here. I used this to calculate a CRC checksum:

test_string:='teststring';
CRCstreamInit($0810);
tst_crc:= CRCstreamAddP(@test_string, 10);
WriteLn(SerOut, 'CRC: ['+IntToHex(tst_crc)+']');

What I get is a "D91C", but the correct result should be "C02A" ( assuming the CRC start value is $0000, but even if I calculate with a start value of $FFFF and a seed/ poly of $0810 I should get $6068) so it doesn't add up.

I'm using Compiler Version 4.93.08 Date 080501

Any Ideas?

Uli
uli
 
Avatar
 
Subject:

this seems to work

 · 
Posted: 08.01.2011 - 17:56  ·  #2
Ok,

I tried this and it seems to work:

Code

function CRCString(pSData : pointer to string; seed : word; crc_init : word): word;
var
crc      : word;
i, j     : Byte;

begin
crc:= crc_init;

for j:=1 to Length(pSData^) do
  crc:= crc xor (Word(pSData^[j]) shl 8);
  for i:=1 to 8 do
    if (crc >$7FFF) then
      crc:= (crc shl 1) xor seed;
    else
      crc:= crc shl 1;
    endif;
  endfor;
endfor;

return(swap(crc));
end;

------------------------------------------------------
test_string:='teststring';
tst_crc:= CRCString(@test_string, $0810, $0000);
WriteLn(SerOut, 'CRC: ['+IntToHex(tst_crc)+']');


Not shure what or how exactly the CRCstreamAddP function calculates or if I was using it in a wrong way...

Uli
Avra
Schreiberling
Avatar
Gender:
Location: Belgrade, Serbia
Age: 53
Homepage: rs.linkedin.com/in…
Posts: 653
Registered: 07 / 2002
Subject:

Re: CRC Stream

 · 
Posted: 12.01.2011 - 09:45  ·  #3
Quote by uli
Not shure what or how exactly the CRCstreamAddP function calculates or if I was using it in a wrong way...

The first byte in a pascal string is the length of the string, not the first character of the string.
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 15 · Cache Hits: 14   60   74 · Page-Gen-Time: 0.021607s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI