Autor Beitrag
Pbg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16

Win 98
D3 Prof.
BeitragVerfasst: Sa 05.07.03 21:45 
Hallo,

ich habe in einer Datei folgende Hex Zahlen

04 03 36 65 52 00

diese Werte möchte ich aus der Datei lesen und mir anzeigen lassen. Die Zahl muesste 3665,52 heissen. Ich dachte es ist real48 (wegen den 6 byte) aber das klappt nicht Ich weiss nicht ob die ersten beiden Zahlen ( 04 03 ) mit dazu gehören. Weiss jemand unter welchen Format diese Zahlen gespeichert sind ?

Danke
MfG
worm
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 135


D6 Prof
BeitragVerfasst: Sa 05.07.03 23:06 
Wenn die Zahl 3665,52 heißen soll, glaube ich nicht, dass das Hex-Zahlen sind, sonst würde dort nicht die Folge 36 65 52 drin vorkommen :!:
Um herauszufinden, wie das nun wirklich gespeichert ist, bräuchte man ein paar mehr Beispiele. Hast Du noch welche?

_________________
In the beginning, the universe was created. This has made a lot of people very angry, and is generally considered to have been a bad move.
Pbg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16

Win 98
D3 Prof.
BeitragVerfasst: Sa 05.07.03 23:39 
Hallo,

die Zahl ist wirklich hex habe Sie mit dem Hex Editor gelesen und gebe sie auch selbst ein, aber eben über ein altes dos Programm wo ich nicht weiss wie er es speichert, habe schon integer , strings gefunden nur die Werte mit den er rechnet also Gleitkommazahlen die speichert er so ab :o( . Durch Datei vergleichen habe ich die Stellen gefunden wo der geänderte Wert steht. und an den Zahlen erkennt man es ja auch.

MfG
worm
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 135


D6 Prof
BeitragVerfasst: So 06.07.03 00:06 
Hmm, ist dann aber sehr merkwürdig gespeichert. Der scheint das ja dann dezimal zu speichern und immer 4 Bits pro (Dezimal-)Ziffer zu nehmen, sonst würdest Du nicht die richtigen Zahlen dort stehen haben (im Hexeditor).
Man braucht aber trotzdem noch ein paar weitere Beispiele... z.B. 1, 100000, 1.12345, um zu sehen, ob und wie die Position des Kommas gespeichert wird. Irgendwie müssen diese (und andere?) Informationen ja noch in den ersten beiden Bytes gespeichert sein. Dort könnte die Länge gespeichert sein (oder sind die Zahlen generell 0-terminiert wie in dem einen Beispiel?) und auch die Position des Kommas.

_________________
In the beginning, the universe was created. This has made a lot of people very angry, and is generally considered to have been a bad move.
Pbg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16

Win 98
D3 Prof.
BeitragVerfasst: So 06.07.03 12:30 
Hallo,

das ist ein Teil von so einen Satz, der erste Teil ist text 8115944221100. dann ein paar stellen die ich noch nicht getestet habe und dann sind die Zahlen
ausblenden Quelltext
1:
2:
1569,72   9564,71  4301,48 
6352,95   3665,62   6952,14


ausblenden Quelltext
1:
2:
3:
4:
38 31 31 35 39 34 34 32 32 31 31 30 30 86 21 04
03 25 89 45 00 04 03 15 69 72 00 04 03 95 64 71
00 04 03 43 01 58 00 04 03 63 52 95 00 04 03 36 
65 52 00 04 03 16 99 45 00 04 03 69 52 14 00

in einer anderen Datei sind die Zahlen 7 Stellig dort beginnden sie mit 04 04 und weiter 98 76 54 30 muß heissen 98765,43. Mit den Zahlen wird in den Programm gerechnet.

MfG

Moderiert von user profile iconTino: Code-Tags hinzugefügt.
lb
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27

Win98, win2000, winxp, linux
D5,Kylix
BeitragVerfasst: So 06.07.03 14:41 
Titel: HEX Zahlen einlesen
Also ich hab probiert ein programm zu Schreiben, was Hexzahlen einliesst. Da kommt aber etwas anderes bei raus als bei dir.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Button1Click(Sender: TObject);
var
 r : real;
 i: longint;
 p: ^real;
begin
 i := StrToInt(Edit1.Text);
 p := Addr(i);
 r := p^;
 label1.Caption := FloatToStr(r);
end;

In Edit1 wird eine longint Zahl i eingelesen (Hex und Longint laesst sich einfach Konvertieren), dann einen real Pointer der Addresse von i zugeordnet und dem Wert p^ dann wiederum ein Realwert zugeordnet. Da kommt aber etwas anderes heraus als von dir gewuenscht :cry: .

Bei dem von dir gefragtem Format wuerde ich selbst ein kleines Programm schreiben, welches die Werte einliest.

Moderiert von user profile iconTino: Delphi-Tags hinzugefügt.

_________________
Aus dieser hohlen Gasse muss er kommen
Guesse Lutz
Pbg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16

Win 98
D3 Prof.
BeitragVerfasst: So 06.07.03 15:42 
Hallo,

Danke Dir ! Meine Zahlen müssen dabei rauskommen. Ich habe wahrscheinlich gefunden wie es gespeichert ist
ausblenden Delphi-Quelltext
1:
Typ TBcd					

habe es jetzt so declariert
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
  type
  TBcd  = packed record
    Precision: Byte;         { 1..64 }
    SignSpecialPlaces: Byte; { Sign:1, Special:1, Places:6 }
    Fraction: packed array [0..3of Byte; { BCD Nibbles, 00..99 per Byte, high Nibble 1st }
     end;

   var Geld1, geld2, geld3 : tbcd;

beim einlesen dann
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
type Stammdaten = packed record
    zahl1 : longint;
    zahl2 : longint;
    zahl3 : longint;
        u.s.w

dann
ausblenden Delphi-Quelltext
1:
2:
3:
        geld1 : tbcd;
        geld2 : tbcd;
  geld3 : tbcd;

aber wie wandle ich das nun um, damit ich damit rechnen kann oder es anzeigen.

In der Delphi Hilfe steht TBCDField.AsString er bringt bei mir das er asstring nicht kennt. Bin Neuling in Delphi weiss mit property nichts anzufangen.

MfG

Moderiert von user profile iconTino: Delphi-Tags hinzugefügt.
lb
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27

Win98, win2000, winxp, linux
D5,Kylix
BeitragVerfasst: Sa 12.07.03 10:28 
Titel: 'HexDaten' einlesen: ein kleines DemoProgramm!
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:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;


var
  Form1: TForm1;
  str : string;

const s = '04 03 36 65 52 00';

implementation

{$R *.DFM}


procedure TForm1.Button1Click(Sender: TObject);
begin
  str := s[7] + s[8] + s[10]+ s[11]+'.' + s[13] + s[14] + s[16] + s[17];
  Label1.Caption := str;
end;

procedure TForm1.Button2Click(Sender: TObject);
var r : real;
begin
 r := StrToFloat(str) + 2.34;
 label1.Caption := FloatToStr(r);
end;

end.


So wuerde ich es machen!! Und wie das Demo zeigt, laesst es sich auch mit der Zahl rechnen!

Moderiert von user profile iconTino: Delphi-Tags hinzugefügt.

_________________
Aus dieser hohlen Gasse muss er kommen
Guesse Lutz
Pbg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16

Win 98
D3 Prof.
BeitragVerfasst: Mi 23.07.03 14:25 
Hallo,
Danke für Deine Antwort, kam lange nicht zum Prog.
deshalb jetzt erst meine Antwort.
ich habe es jetzt so gemacht, die Zahlen von der Funktion sind 7 Stellig
die alten waren 6. Ist aber ähnlich. Ich übergebe 4 Zahlen je 1 byte
zb. 64 , 34, 72, 40 (das ist der Inhalt der Bytes in Hex) und rauskommen muss 64347,24

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:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
//  **************** BCD  Funktion umrechnen *****************************
//  **********  4 Byte von BCD nach Float ****************************
function TForm1.umrechnen(zahl, zahl1, zahl2 ,zahl3 : integer):Currency ;
var
hbyte1: integer;
hbyte2: integer;
h: integer;
h1: integer;
erstezahl : integer;
zweitezahl: integer;
drittezahl: integer;
viertezahl: integer;
summe: integer;
summe1 : Currency;

begin;
// erste Zahl
h:= zahl div 16;
hbyte2:= zahl - (h * 16);
h1:= h div 16;
hbyte1:= h - (h1 * 16);
erstezahl := (hbyte1 * 10) + hbyte2;

// zweite Zahl
h:= zahl1 div 16;
hbyte2:= zahl1 - (h * 16);
h1:= h div 16;
hbyte1:= h - (h1 * 16);
zweitezahl := (hbyte1 * 10) + hbyte2;

// dritte Zahl
h:= zahl2 div 16;
hbyte2:= zahl2 - (h * 16);
h1:= h div 16;
hbyte1:= h - (h1 * 16);
drittezahl := (hbyte1 * 10) + hbyte2;

// vierte Zahl nur erstel Halbbyte
h:= zahl3 div 16;
//hbyte2:= zahl2 - (h * 16);
//h1:= h div 16;
//hbyte1:= h - (h1 * 16);
//viertezahl := (hbyte1 * 10) + hbyte2;
  viertezahl := h;


//  Alle Zahlen zusammenfassen
erstezahl := erstezahl*100000;
zweitezahl := zweitezahl * 1000;
drittezahl := drittezahl * 10;
summe:= erstezahl+zweitezahl+drittezahl+viertezahl;

  summe1 := summe / 100;

  edit11.text := IntToStr(erstezahl);
  edit12.text := IntToStr(zweitezahl);
  edit13.text := IntToStr(drittezahl);
  edit14.text := IntToStr(viertezahl);
  edit15.text := IntToStr(summe);

result := summe1;
end;

// ***************************  Ende Funktion umrechnen **************
// *******************************************************************

Mit BCDField wäre es sicher einfacher gewesen, weiss eben bloß nicht wie :o))
Hat jemand eine kürzere Version ?
MfG

Moderiert von user profile iconKlabautermann: Delphi-Tags hinzugefügt.
lb
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27

Win98, win2000, winxp, linux
D5,Kylix
BeitragVerfasst: Do 24.07.03 22:37 
ausblenden volle Höhe 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:
function TForm1.umrechnen(zahl, zahl2 ,zahl3,zahl4 : integer):Currency ;
var
erstezahl : integer;
zweitezahl: integer;
drittezahl: integer;
viertezahl: integer;
summe: integer;
summe1 : Currency;
s: string;
begin;
// erste Zahl
erstezahl := StrToInt(IntToHex(Zahl,2));

// zweite Zahl
zweitezahl := StrToInt(IntToHex(Zahl2,2));

// dritte Zahl
drittezahl := StrToInt(IntToHex(Zahl3,2));

// vierte Zahl nur erstel Halbbyte
s := IntToHex(Zahl4,2);
viertezahl := StrToInt(s[1]);


//  Alle Zahlen zusammenfassen 
erstezahl := erstezahl*100000; 
zweitezahl := zweitezahl * 1000;
drittezahl := drittezahl * 10; 
summe:= erstezahl+zweitezahl+drittezahl+viertezahl; 

  summe1 := summe / 100; 
  Edit1.Text := IntToStr(erstezahl);
  Edit2.Text := IntToStr(zweitezahl);
  Edit3.Text := IntToStr(drittezahl);
  Edit4.Text := IntToStr(viertezahl);
  Edit5.Text := IntToStr(summe);

result := summe1;
end;

// ***************************  Ende Funktion umrechnen **************
// *******************************************************************

So sieht es einfacher aus, jedoch bekomme ich mit diesem Programm ein anderes Ergebniss: Wenn ich 64,34,72,40 wird die Zahl in 40224,82 umgewandelt und nicht wie gewuenscht in 64347,24!!!

_________________
Aus dieser hohlen Gasse muss er kommen
Guesse Lutz
lb
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27

Win98, win2000, winxp, linux
D5,Kylix
BeitragVerfasst: Do 24.07.03 22:38 
ausblenden volle Höhe 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:
function TForm1.umrechnen(zahl, zahl2 ,zahl3,zahl4 : integer):Currency ;
var
erstezahl : integer;
zweitezahl: integer;
drittezahl: integer;
viertezahl: integer;
summe: integer;
summe1 : Currency;
s: string;
begin;
// erste Zahl
erstezahl := StrToInt(IntToHex(Zahl,2));

// zweite Zahl
zweitezahl := StrToInt(IntToHex(Zahl2,2));

// dritte Zahl
drittezahl := StrToInt(IntToHex(Zahl3,2));

// vierte Zahl nur erstel Halbbyte
s := IntToHex(Zahl4,2);
viertezahl := StrToInt(s[1]);


//  Alle Zahlen zusammenfassen 
erstezahl := erstezahl*100000; 
zweitezahl := zweitezahl * 1000;
drittezahl := drittezahl * 10; 
summe:= erstezahl+zweitezahl+drittezahl+viertezahl; 

  summe1 := summe / 100; 
  Edit1.Text := IntToStr(erstezahl);
  Edit2.Text := IntToStr(zweitezahl);
  Edit3.Text := IntToStr(drittezahl);
  Edit4.Text := IntToStr(viertezahl);
  Edit5.Text := IntToStr(summe);

result := summe1;
end;

// ***************************  Ende Funktion umrechnen **************
// *******************************************************************

So sieht es einfacher aus, jedoch bekomme ich mit diesem Programm ein anderes Ergebniss: Wenn ich 64,34,72,40 wird die Zahl in 40224,82 umgewandelt und nicht wie gewuenscht in 64347,24!!!

_________________
Aus dieser hohlen Gasse muss er kommen
Guesse Lutz
lb
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27

Win98, win2000, winxp, linux
D5,Kylix
BeitragVerfasst: Do 24.07.03 22:50 
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:
function TForm1.umrechnen(zahl, zahl2 ,zahl3,zahl4 : integer):Currency ;
var
summe: integer;
summe1 : Currency;
s: string;
begin;
// vierte Zahl nur erstel Halbbyte
s := IntToStr(Zahl4);
zahl4 := StrToInt(s[1]);


//  Alle Zahlen zusammenfassen
summe:= zahl*100000 + zahl2 * 1000 + zahl3 * 10 + zahl4;

  summe1 := summe / 100;
  Edit1.Text := IntToStr(zahl);
  Edit2.Text := IntToStr(zahl2);
  Edit3.Text := IntToStr(zahl3);
  Edit4.Text := IntToStr(zahl4);
  Edit5.Text := IntToStr(summe);

result := summe1;
end;

So kommt das gewuenschte Ergebniss heraus!!! :lol:

_________________
Aus dieser hohlen Gasse muss er kommen
Guesse Lutz
Pbg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16

Win 98
D3 Prof.
BeitragVerfasst: Fr 25.07.03 12:18 
Hallo ,
Danke für Deine Hilfe.
Die hex Umwandlung kannte ich nicht.
Ich habe es jetzt so gemacht

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:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
//  **************** BCD  Funktion  geht nur bis Länge 4 ******************
//  **********  4 Byte von BCD nach Currency ****************************
function TForm1.umrechnen(zahl, zahl1, zahl2 ,zahl3, stelle : integer):Currency ;
var
h: integer;
erstezahl : integer;
zweitezahl: integer;
drittezahl: integer;
viertezahl: integer;
summe: integer;
summe1 : Currency;

begin;
erstezahl := StrToInt(IntToHex(Zahl,2));

// zweite Zahl
zweitezahl := StrToInt(IntToHex(Zahl1,2));

// dritte Zahl
drittezahl := StrToInt(IntToHex(Zahl2,2));

// vierte Zahl nur erstel Halbbyte          
h:= zahl3 div 16;                                       
viertezahl := h;

//  Alle Zahlen zusammenfassen
if stelle = 4 then  begin                                 
erstezahl := erstezahl*100000;
zweitezahl := zweitezahl * 1000;
drittezahl := drittezahl * 10;
end;

if stelle = 3 then  begin
erstezahl := erstezahl*10000;
zweitezahl := zweitezahl * 100;
end;

if stelle = 2 then  begin
erstezahl := erstezahl*1000;
zweitezahl := zweitezahl * 10;
end;

if stelle = 1 then  begin
erstezahl := erstezahl*100;
end;

if stelle = 0 then  begin
erstezahl := erstezahl*10;
zweitezahl := zweitezahl div 10;
end;

//braucht man nicht 
if stelle = 129 then  begin
//erstezahl := erstezahl div 10;
end;

summe:= erstezahl+zweitezahl+drittezahl+viertezahl;
summe1 := summe / 100;

  edit11.text := IntToStr(erstezahl);
  edit12.text := IntToStr(zweitezahl);
  edit13.text := IntToStr(drittezahl);
  edit14.text := IntToStr(viertezahl);
  edit15.text := IntToStr(summe);

result := summe1;
end;

// ***************************  Ende Funktion umrechnen **************
// *******************************************************************


Ich musste doch das 2 Byte verwenden ( Ist die Längenangabe)
Ich hatte nicht bedacht das es auch Werte in der Datei gibt die zb 0,23 oder 23,50 sind :o))
2tes byte hex 81 bedeutet 0,12
2tes byte hex 00 bedeutet 1,20
2tes byte hex 01 bedeutet 12,00 u.s.w. geht in meinen Fall nur bis 4


MfG

Moderiert von user profile iconKlabautermann: Delphi-Tags hinzugefügt.