Autor Beitrag
DeltaEx
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 110



BeitragVerfasst: Di 03.05.05 11:07 
Ich habe ein Problem :wink:

Und zwar habe ich ein Edit1. Wenn mann da z.B. jetzt Hallo eingibt,
soll H = 48
a = 61
l= 6C
l = 6C
o = 6F
---------------
1F0

addiert werden.

Wie kann ich das realisieren? Wie rechne ich mit Hex?

Danke für die Mühe

_________________
Delphi forever
Holgerwa
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 325

WIN XP Pro, Vista Business
Delphi 7 Pro, BDS 2006 Pro
BeitragVerfasst: Di 03.05.05 11:09 
Hallo,

rechne doch erst die dezimalen Codes zusammen, und wandle dann nur das Ergebnis in Hex um. Das sollte einfacher sein.

Holger
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Di 03.05.05 11:23 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Button1Click(Sender: TObject);
var i :Integer;
    Count : Integer;
begin
  Count := 0;
  for i := 1 to length(Edit1.Text) do Count := Count + ord(Edit1.Text[i]);
  showmessage(IntToHex(count,8));
end;

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.
NeoInDerMATRIX
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 245

Win95, Win98(+se), WinNT, Win2000, WinME, WinXP(+pro), VISTA, Linux(SuSe), DOS [MultiMon(3)], Vista
D6 PeE + (FP 2.0l) + D3 Pe + D2005+ D2006 Arch
BeitragVerfasst: Di 03.05.05 11:27 
Hi,

es ist egal b du mit integer oder Hexwerten rechnest es sollte immer das gleiche rau kommen.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
Function CalcString(AString: String): Integer;
Var
 Lauf: Integer;
 Temp: Integer;
Begin
 Temp:=0;
 For Lauf:=0 to LEngth(AString) do
   Temp:=Temp + Byte(AString[Lauf]);
 Result:=Temp;
End;

procedure TForm1.Label1Click(Sender: TObject);
begin
 Label1.Caption:=IntToHex(CalcString('Hallo'), 4);
end;


Probiers mal so!

Cu
Neo

//Edit: Meno alle sind se schneler wie ich! :?
DeltaEx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 110



BeitragVerfasst: Di 03.05.05 11:31 
Ja danke das funzt. Was ist eigentlich das Ord() ?? In der Delphi-Hilfe finde ich es nicht.

_________________
Delphi forever
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Di 03.05.05 11:34 
Ord returns the ordinal value of an ordinal-type expression.

Unit

System

Category

ordinal routines

function Ord(X): Longint;

Description

X is an ordinal-type or character-type expression. The result is of type Longint, and its value is the ordinal position of X.

Ord cannot operate on Int64 values.

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Di 03.05.05 11:53 
user profile iconHolgerwa hat folgendes geschrieben:
Hallo,

rechne doch erst die dezimalen Codes zusammen, und wandle dann nur das Ergebnis in Hex um. Das sollte einfacher sein.

Holger

Genau, die Grundoperationen (+, -, usw) sind natürlich unabhängig vom Zahlensystem. Der Computer rechnet schlussendlich alles im Binärsystem (nicht etwa im Dezimalsystem), nur merkst du davon nichts.