Autor Beitrag
CASS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 160

WIN XP
D7 Enterprise
BeitragVerfasst: Mo 12.12.05 15:05 
Hi Leute,

ich hoffe ich bin jetzt in der richtigen Kategorie gelandet ... *hoff*

Folgendes Problem:
Ich hab ein Beispiel zur Berechnung einer CRC Checksumme in Basic, diese muss ich jetzt auf Delphi umsetzten.
Leider will mir das nicht so ganz gelingen.

Hier der Basic Code:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
crc16& = 65535
FOR c% = 1 to LEN(message$)
crc16& = crc16& XOR ASC(MID$(message$, c%, 1))
FOR bit% = 1 to 8
IF crc16& MOD 2 THEN
crc16& = (crc16& \ 2) XOR 40961
ELSE
crc16& = crc16& \ 2
END IF
NEXT BIT%
NEXT c%
crch% = CRC16& \ 256: crcl% = CRC16& MOD 256
message$ = message$ + CHR$(crcl%) + CHR$(crch%)
CRC = CRC16&
END FUNCTION CRC


Und hier der Delphi Code den ich bis jetzt hab:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
function crc (command: string): string;
var
  Crc16, i, Bit: Integer;
  Crch, Crcl: Byte;
begin
  Crc16 := 65535;
  for i := 1 to Length(Command) do
  begin
    Crc16 := Crc16 XOR StrToInt(Command[i]);
    for Bit := 1 to 8 do
    begin
      if (Crc16 mod 2) = 1 then
      begin
        Crc16 := (Crc16 \ 2XOR 40961;
        end
      else
        Crc16 := Crc16 / 2;
      end;
    end;
  Crch := Crc16 / 256;
  Crcl := Crc16 MOD 256;
  Command = Command + Chr(Crcl) + Chr(Crch);

  Result := Command;
end;


Könnt ihr mir sagen für was das \ bei Basic steht? Und ob der rest so richtig umgesetzt ist.

Danke für jede Hilfe schon im Voraus,
Cass
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 12.12.05 15:53 
Moin!

Suchst du: Suche in: Delphi-Forum, Delphi-Library CRC OR CRC16

cu
Narses
CASS Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 160

WIN XP
D7 Enterprise
BeitragVerfasst: Mo 12.12.05 16:29 
Ich denk nicht das es ein Standard CRC16 ist, kann ich aber leider auch nicht genau sagen. Aber die Sache muss ganz simpel sein. Ist zur Steuerung eines Thermometers.
CASS Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 160

WIN XP
D7 Enterprise
BeitragVerfasst: Mo 12.12.05 17:38 
Kann mir denn jemand erklären für was der \ bei der Basic Programmierung stehen soll?
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Mo 12.12.05 17:49 
Nee, vermutlich irgendwas mit shift, rotate oder so...
Aber hier, nimm das hier (falls Du es nicht für eine HA benötigst)
Einloggen, um Attachments anzusehen!
_________________
Na denn, dann. Bis dann, denn.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mo 12.12.05 18:09 
In beiden Fällen ist ein simples DIV gemeint. Zumindest verarbeitet das QBasic so ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Mo 12.12.05 18:13 
VB ist doch echt das Beste! :mrgreen:

_________________
Na denn, dann. Bis dann, denn.