Autor Beitrag
sourcehunter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 482

Win XP | Suse 10.1
Delphi 2005 Pers.
BeitragVerfasst: Fr 08.10.04 15:20 
Kann mir jemand sagen, wie ich einen beliebigen Realtyp in ein Array of Byte umwandeln kann? Mit Integern kann ich es wie folgt machen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
for i:=0 to size-1 do
begin
   bytes[i]:=int and $FF;
   int:=int SHR 8;
end;


Das klappt bei Reals nicht, denn ich kann weder ein and noch ein SHR auf einen Realtyp anwenden.

_________________
Linux und OpenSource rulez!
greg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 119

Windows2000, WindowsXP
D5 Prof
BeitragVerfasst: Fr 08.10.04 15:36 
Hallo Sourcehunter,

ich weiss zwar nicht genau wie, aber das Einfachste und Schnellste dürfte wohl sein, wenn Du Dir den Zeiger auf die Variable besorgst und die Bytes (je nach Datentyp) direkt aus dem Speicher liest.

Gruß
Gregor
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 08.10.04 15:44 
@sourcehunter:
Was hast du denn damit vor???
Du weist hoffentlich, dass Fließkommazahlen ganz anders dargestellt werden, als Integer und Co.
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Fr 08.10.04 15:45 
Eine Anwendung wäre ein Data Inspector, z.B. in einem Hex-Editor. ;-)

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!
sourcehunter Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 482

Win XP | Suse 10.1
Delphi 2005 Pers.
BeitragVerfasst: Fr 08.10.04 16:25 
@jasocul: Ja, ich weiß das, deshalb will ich das ja wissen. :wink:
@greg: Auf die Idee hätte ich selber kommen können. Danke.

_________________
Linux und OpenSource rulez!
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Fr 08.10.04 16:33 
also:

s := format(%f,[realzahl];
delete(s,pos(',',s),1);

for i := 1 to length(s) do
dasarray[i] = ord(s[i])-ord('0')
sourcehunter Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 482

Win XP | Suse 10.1
Delphi 2005 Pers.
BeitragVerfasst: Fr 08.10.04 17:09 
Nein nicht solche Bytes. Echte Bytes, wie sie im Scheicher liegen. Ich habe Das Problem inzwischen so gelöst:

ausblenden Delphi-Quelltext
1:
2:
{bytes:Array of Byte}
bytes:=Pointer(@float);

_________________
Linux und OpenSource rulez!