Autor Beitrag
DD
ontopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 41

Win 2000
D6 Pers
BeitragVerfasst: So 09.11.03 14:40 
Wer kann mir folgenden Sourcecode erklären:
ausblenden volle Höhe 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:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
var
  Form1: TForm1;
  BZ: string;
  GT,R,Zahl,p,anzahl,i: integer;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
 zahl:=strtoint (edit1.text);
 GT:=Zahl;
 BZ:=' ';
 while GT <> 0 do
 begin
  R:=GT mod 16;
  GT:=Gt div 16;
  case R of                   
  0..9: BZ:=inttostr(R)+BZ;
  10: BZ:='A'+BZ;
  11: BZ:='B'+BZ;
  12: BZ:='C'+BZ;
  13: BZ:='D'+BZ;
  14: BZ:='E'+BZ;
  15: BZ:='F'+BZ;
  end;
  {p:=p+1}
 end;
  p:=length(BZ);
  anzahl:=4-p;
 for i:=0 to anzahl do
 begin
  BZ:= '0'+BZ;
 end;
  edit2.Text:=BZ;
end;


end.

Insbesondere die Stelle mit der Case-Anweisung und das kleine Stück davor bereitet mir Kopfzerbrechen. Bitte um schnelle Hilfe

Danke im Vorraus
DD

Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.

_________________
Never change a running system!
obbschtkuche
Gast
Erhaltene Danke: 1



BeitragVerfasst: So 09.11.03 15:15 
Der Code wandelt eine Int-Zahl in hex-dezimalschreibweise um. Da das hexadezimalsystem ein 16-er system ist, wird hiermit:

ausblenden Delphi-Quelltext
1:
2:
  R:=GT mod 16; 
  GT:=Gt div 16;


jeweils ein Zeichen des Ergebnisses ermittelt, wobei 0-9 unverändert bleibt und 10-15 für A-F steht.
Am Ende werden noch fehlende 0en angehängt, falls das Ergebnis kürzer als 4 Stellen ist.
Dafür gibt es übrigens "IntToHex"