Autor Beitrag
Noob23
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 93

Win XP, Win Server 2003, Win 7, Ubuntu
Delphi 7, c/c++ Dev-c++, µC-8051 Keil, Webdesign Notepad++
BeitragVerfasst: Sa 22.03.08 15:18 
hallo zusammen,

leider komme ich bei der übersetzung von folgendem c-code nach delphi nicht weiter
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
uint32_t crc32(unsigned char *data, int size) {
  const static uint32_t crctable[] = {0x00000000,0x77073096,...[weitere daten]...,0x5a05df1b,0x2d02ef8d};
  uint32_t crc = 0xffffffff;
  while(size--) {
    crc = crctable[*data ^ (crc & 0xFF)] ^ (crc >> 8);
    data++;
  }
  return(~crc);
}

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
Const crctab : Array[0..255] of Int64 = ($00000000, $77073096,...[weitere daten]..., $5a05df1b, $2d02ef8d);

Function Crc32(data:string): longword;
var crc : longword;
    len : integer;
begin
  crc := $ffffffff;
  for len := 1 to length(data) do
  begin
    crc := (crctab[Ord(data[len]) XOR (crc AND 255)] XOR (crc shr 8));
  end;
  result := crc;
end;



hat jemand eine idee was hier falsch sein könnte?

Danke :)

Gruß Noob23


Moderiert von user profile iconNarses: Topic aus Sonstiges (Delphi) verschoben am Sa 22.03.2008 um 15:46
Chryzler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1097
Erhaltene Danke: 2



BeitragVerfasst: Sa 22.03.08 15:54 
return(~crc); heißt soweit ich weiß Result := not crc;
Dann könnte man sich die crc-Variable noch sparen, weil du ja am Ende sowieso Result das Ergebnis zuweist:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
function Crc32(data: String): Longword;  
var
  len: Integer;  
begin  
  Result := $FFFFFFFF;  
  for len := 1 to Length(data) do  
    Result := crctab[Ord(data[len]) xor (Result and 255)] xor (Result shr 8);
  Result := not Result;  
end;

Ob noch andere Fehler drin sind weiß ich nicht, mir ist nur grad der aufgefallen.
Noob23 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 93

Win XP, Win Server 2003, Win 7, Ubuntu
Delphi 7, c/c++ Dev-c++, µC-8051 Keil, Webdesign Notepad++
BeitragVerfasst: Sa 22.03.08 16:20 
danke :)

es funktioniert jetz soweit ... nur noch in hex wandeln und bytes untereinander tauschen dann sollt es tun
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 22.03.08 16:44 
user profile iconChryzler hat folgendes geschrieben:
return(~crc); heißt soweit ich weiß Result := not crc;

Nein, die Negation in C ist "!".
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Sa 22.03.08 16:51 
Die Boolsche Negation ist !, aber hier gehts wohl um die bitweise Negation ~, und das entspricht in Delphi einem not.

_________________
We are, we were and will not be.
Noob23 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 93

Win XP, Win Server 2003, Win 7, Ubuntu
Delphi 7, c/c++ Dev-c++, µC-8051 Keil, Webdesign Notepad++
BeitragVerfasst: Sa 22.03.08 17:06 
dass "!" in C eine negation ist hät ich auch noch hinbekommen, aber das war nicht die frage ;)

und ich hatte doch geschrieben es geht :D