Autor Beitrag
Tobias1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 454

Win 98, XP Prof
D3 Prof, D2005 Prof
BeitragVerfasst: So 24.04.05 21:08 
user profile icondelfiphan hat folgendes geschrieben:

Oder die Lösung von Tobias1 (habs nicht getestet), obwohl meiner Meinung nach die Rechnung mit Gleitkommazahlen nicht so elegant ist und beim Edit1.Text[] jedes mal eine Methode (TControl.GetText) aufgeruft werden muss, was eigentlich unnötig ist.

Du hast recht aber ich denk es ist vielleicht so besser nachvollziehbar.

_________________
Auch das schlechteste Buch hat seine gute Seite: die letzte. (John Osborne)
Tobias1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 454

Win 98, XP Prof
D3 Prof, D2005 Prof
BeitragVerfasst: So 24.04.05 21:09 
user profile iconBuchi hat folgendes geschrieben:

Nur muss der Case-Befehl diesmal vor der Rechnerei stehen. Oder?


Ja, denn ich will ja wissen mit was ich rechne.

_________________
Auch das schlechteste Buch hat seine gute Seite: die letzte. (John Osborne)
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: So 24.04.05 21:13 
Das hier müsste eigentlich klappen (sorry, vorher hatte ich IntToStr geschrieben, statt StrToInt).
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
function HexToInt(const S: String): Integer;
var
 I, Ziffer: Integer;
begin
 Result := 0;
 for I := 1 to length(S) do
 begin
  Case S[I] of
   '0'..'9': Ziffer := StrToInt(S[I]);
   'A': Ziffer := 10;
   'B': Ziffer := 11;
   'C': Ziffer := 12;
   'D': Ziffer := 13;
   'E': Ziffer := 14;
   'F': Ziffer := 15;
  end;
  Result := Result*16 + Ziffer;
 end;
end;

(PS: Wie gesagt, so würde man das üblicherweise nicht programmieren, jedoch sollte das jetzt nachvollziehbar sein. :))
Buchi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 33

Win XP
Delphi 6 Professional
BeitragVerfasst: So 24.04.05 21:19 
Ok. Ich versuch mal das Programm im Stil vom anderen zu schreiben...
Weiß aber jetzt schon dass ich das net hinkrieg. Hab auch langsam kein Nerv mehr, Test hin oder her.

Danke für eure Hilfe, Zeit und fürs Bemühen

_________________
AMD Athlon64 3700+ | 1536MB RAM | Geforce 7800GT
Tobias1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 454

Win 98, XP Prof
D3 Prof, D2005 Prof
BeitragVerfasst: So 24.04.05 21:21 
Viel Glück! :wink:

_________________
Auch das schlechteste Buch hat seine gute Seite: die letzte. (John Osborne)
Buchi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 33

Win XP
Delphi 6 Professional
BeitragVerfasst: So 24.04.05 21:24 
Danke, hoffe ich habe euch nicht zu arg genervt

_________________
AMD Athlon64 3700+ | 1536MB RAM | Geforce 7800GT
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: So 24.04.05 21:42 
Nein, überhaupt nicht, ganz im Gegenteil. Wünsche dir auch viel Glück.
Und wenn du etwas nicht verstehst, gibt's ja das Forum :)
Phantom1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 390



BeitragVerfasst: So 24.04.05 21:53 
Falls du auch mal in andere Basis-Systeme umrechnen willst, ist dieser code von DelphiPraxis.de ganz nützlich:

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:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
function Potenz(Base, Exp: Integer): Int64;
var i: Integer;
begin
  Result:=1;
  for i:=1 to Exp do
    Result:=Result * Base;
end;

function GetChar(Number: Byte): Char;
begin
  Result:=' ';
  case Number of
      0..9: Result:=Chr(Number+48);
    10..35: Result:=Chr(Number+55);
  end;
end;

function GetInt(Value: Char): Byte;
begin
  Result:=0;
  case Value of
    '0'..'9': Result:=Ord(Value)-48;
    'A'..'Z': Result:=Ord(Value)-55;
    'a'..'z': Result:=Ord(Value)-87;
  end;
end;

function DecToBase(Value: Int64; Base: Byte): String;
begin
  repeat
    Result:=GetChar(Value mod Base) + Result;
    Value:=Value div Base;
  until Value=0;
end;

function BaseToDec(Value: String; Base: Byte): Int64;
var i, j: Integer;
begin
  Result:=0;
  j:=0;
  for i:=Length(Value) downto 1 do begin
    Result:=Result + GetInt(Value[i]) * Potenz(Base, j);
    inc(j);
  end;
end;

function BaseToBase(StartBase: Byte; Value: String; EndBase: Byte): String;
begin
  Result:=DecToBase(BaseToDec(Value, StartBase), EndBase);
end;


Man kann jetzt ganz einfach von einem Basis-System ins andere umwandeln. Zb: vom Binärsystem ins Hexadezimalesystem usw.
Möglich sind die Basen von 1 bis 35 !
Basis 2 ist das Binärsystem, Basis 10 ist das Dezimalsystem, Basis 16 ist das Hexadezimalsystem, usw...

Hier ein paar Beispiele:
ausblenden Delphi-Quelltext
1:
2:
ShowMessage(BaseToBase(2, '101010', 16)); // umrechnung von Binär in Hex
ShowMessage(BaseToBase(10, '12345', 8)); // umrechnung von Dezimal in Oct

MfG
Phantom1
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: So 24.04.05 22:41 
user profile iconBuchi hat folgendes geschrieben:
Nun sollen wir ein Programm schreiben dass umgekehrt, also vom 16er ins 10er System rechnet. Sämtliche Ansätze die ich bisher versucht habe schlugen allerdings fehl. Kann mir jemand helfen?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Button1Click(Sender: TObject);
var
  S: String;
  I: Integer;
begin

  S := '$' + Edit1.Text;
  I := StrToInt(S);
  Label1.Caption := IntToStr(I);

end;

_________________
Ciao, Sprint.
Buchi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 33

Win XP
Delphi 6 Professional
BeitragVerfasst: Mo 25.04.05 16:36 
So, wir haben keinen Test geschrieben. *aufatme* Wir haben stattdessen das Programm im Unterricht noch einmal von Grund auf neu erstellt. Für alle die es interessiert poste ich hier mal den Code...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
var l,i:integer;  x:string; w:array of integer;e:extended; procedure TForm1.Button1Click(Sender: TObject); begin

x:=edit1.text;
l:=length(edit1.text);
setlength(w,l);
for i:=1 to l do
case x[i] of '0'..'9': w[i-1]:=strtoint(x[i]);
             'A': w[i-1]:=10;
             'B': w[i-1]:=11;
             'C': w[i-1]:=12;
             'D': w[i-1]:=13;
             'E': w[i-1]:=14;
             'F': w[i-1]:=15;
             end;
e:=0;
for i:=l-1 downto 0 do
    e:= power(16,l-1-i) * w[i]+e;

label1.caption:=floattostr(e);


Gruß Buchi

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

_________________
AMD Athlon64 3700+ | 1536MB RAM | Geforce 7800GT
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Mi 11.05.05 02:37 
user profile iconPhantom1 hat folgendes geschrieben:
Falls du auch mal in andere Basis-Systeme umrechnen willst, ist dieser code von DelphiPraxis.de ganz nützlich
...

also irgendwie funktioniert dieser code bei mir nicht richtig, weswegen ich mir selber eine funktion geschustert habe (für die umrechnung 0-255 ins binärsystem)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
function dw2system(d,base:dword;strlen:byte):string;
// converts d in a system based on base
// like dw2system(255,2,8) = '11111111'
// or dw2system(255,16,2) = 'FF'
// by retnyg
const cypher = '0123456789ABCEDF';
var i : dword;
begin
   setlength(result,strlen);
   fillchar(pointer(result)^,strlen,48);
   while (d > 0) and (strlen > 0) do begin
     i := d mod base;
     result[strlen] := cypher[i+1];
     dec(d,i);
     dec(strlen);
     d:=d div base;
   end;
end;

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...