Autor Beitrag
Magic2001
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32


Delphi XE2
BeitragVerfasst: Mi 17.07.13 16:08 
Hi,
kann mir bitte jemand erklären wie ich in Delphi XE binary to float und umgekehrt Umwandeln kann?
Ich meine das so wie hier: www.binaryconvert.co...mal=40213EC56D5CFAAD.
0x40213EC56D5CFAAD in 8.62260000000000026432189770276 und anders herum...

Vielen Dank im voraus...
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Mi 17.07.13 16:54 
Moin!

Dieses "Binary" ist nur eine Darstellung für die nicht-binären Menschen, intern ist das alles das Gleiche :mahn:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
var
  d: double;
begin
  d:= 8.62260000000000026432189770276;
  ShowMessage(IntToHex(PInt64(@d)^,16));

Bzw. Single/Integer für die 32bit-Typen.

Andersrum ist natürlich immer interessant, ob eine bestimmte "Zahl" überhaupt als Float-Wert irgendwas sinnvolles ergibt. Die Idee ist aber die gleiche, einfach nur die Daten im Speicher als etwas anderes behandeln.

Viele Grüße,
Martok

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
Magic2001 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32


Delphi XE2
BeitragVerfasst: Mi 17.07.13 17:58 
Danke, dass funktioniert gut. Aber wie du das mit dem umgekehrten Fall meinst verstehe ich nicht. Hast du da vielleicht auch ein Codeschnipsel ?
Umgekehrt sollte dann eine Float zu Binary sein, in dieser Rechnung funktioniert es auch: www.binaryconvert.co...mal=40213EC56D5CFAAD

Danke!
Gammatester
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 328
Erhaltene Danke: 101



BeitragVerfasst: Do 18.07.13 09:31 
user profile iconMagic2001 hat folgendes geschrieben Zum zitierten Posting springen:
Aber wie du das mit dem umgekehrten Fall meinst verstehe ich nicht.
Nicht jedes Double-Binär-Muster stellt eine gültige Dezimalzahl dar! Versuch mal www.binaryconvert.co...mal=7FFF0123456789AB oder www.binaryconvert.co...mal=FFF0000000000000.
Magic2001 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32


Delphi XE2
BeitragVerfasst: Do 18.07.13 09:39 
Das mag sein aber mein programm arbeitet nur mit gültigen werten! da diese vorher wo anders ausgelesen werden und von meinem programm umgewandelt werden sollen.
Gammatester
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 328
Erhaltene Danke: 101



BeitragVerfasst: Do 18.07.13 09:51 
NaNs und Infs sind gültige Doublewerte, haben aber halt keine Dezimaldarstellung.