Autor Beitrag
Jacko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20



BeitragVerfasst: Do 18.08.05 12:31 
Hi,
ich habe ein DWord. Dieses DWord möchte ich als Double in einem Label darstellen.

Wie wandle ich einen Int- oder Hex-Wert in einen Doublewert um?

danke im Voraus.


Moderiert von user profile iconTino: Topic aus Sonstiges verschoben am Fr 19.08.2005 um 16:14
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: Do 18.08.05 12:41 

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
LigH
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 239

Win98SE, Win2000SP4
D7
BeitragVerfasst: Do 18.08.05 13:31 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var
  i: Integer;
  f: Double;

...
  f := i;

Oder hab ich da was missverstanden?
Jacko Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20



BeitragVerfasst: Do 18.08.05 13:34 
-----------------------------------------------------------------------------------------

Bei dieser Anwendung wird das DWord als Integer interpretiert. Und z.B. bei einem Wert 12 Integer gibt er mir den Wert 12 als Float-Wert zurück.

Ich möchte aber wit den Daten (4Byte) einen Single-Wert haben.

d.h.
Aus Dez '1107820544'(In) sollen Float '34.00'(Out) werden.

gibt es dafür eine Function ?
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: Do 18.08.05 13:37 
user profile iconJacko hat folgendes geschrieben:

Aus Dez '1107820544'(In) sollen Float '34.00'(Out) werden.

gibt es dafür eine Function ?

user profile iconretnyg hat folgendes geschrieben:
Suche in: Delphi-Forum, Delphi-Library FORMATFLOAT

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
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: Do 18.08.05 13:45 
möglichweise meinst du aber auch das
ausblenden Delphi-Quelltext
1:
2:
3:
4:
var x: integer; y: single;
begin
 x:= 44444;
 y:= psingle(@x)^;

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
Jacko Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20



BeitragVerfasst: Do 18.08.05 14:02 
Ich glaube wir reden aneinander vorbei.

ich möchte keine Umformatierung, sondern eine Typumwandlung.

nicht z.B:
von Dez '1'

auf Single '1.00',


sondern z.B:
von Dez '1107820544' (-> Bin 0100_0010_0000_1000_0000_0000_0000_0000)

auf Single '34.00' (-> Bin 0100_0010_0000_1000_0000_0000_0000_0000)
LigH
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 239

Win98SE, Win2000SP4
D7
BeitragVerfasst: Do 18.08.05 14:11 
Dann würde ich das über die "absolute"-Direktive versuchen:

ausblenden Delphi-Quelltext
1:
2:
3:
var
  f: Single; // weil auch 32 bit
  i: Integer absolute f;

Das sorgt dafür, dass beide Variablen exakt die selbe Position im Hauptspeicher belegen, sich also die binäre Repräsentation teilen, aber unterschiedlich behandelt werden können.

Ich hoffe, das geht mit Delphi überhaupt noch?! In Turbo Pascal war's auf jeden Fall möglich. Wenn nicht - versuche die Umwandlung mit PSingle(@int) von retnyg.
Jacko Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20



BeitragVerfasst: Do 18.08.05 14:21 
Danke LigH,

klappt super. :)