| Autor |
Beitrag |
Jacko
      
Beiträge: 20
|
Verfasst: Mo 15.08.05 16:23
Hallo,
ich bekomme in mein Programm SmallInt-Werte aus einer anderen Applikation. Leider sind das Obere und Untere Byte vertauscht.
Wie tausche ich diese Bytes
Danke im Voraus.
|
|
retnyg
      
Beiträge: 2754
SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
|
Verfasst: Mo 15.08.05 16:30
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
| function xchangeBytesSmallint(x:smallint):smallint; asm mov cl, al mov al, ah mov ah, cl end;
procedure TForm1.Button4Click(Sender: TObject); var i: smallint; begin i:=$7700; i:=xchangeBytesSmallint(i); showmessage(inttostr(i)); end; |
_________________ es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
|
|
Allesquarks
      
Beiträge: 510
Win XP Prof
Delphi 7 E
|
Verfasst: Mo 15.08.05 16:30
Könntest die Zahl um acht Bit links oder rechts schieben (natürlich nur wenn sie unsigned ist)
|
|
Stefan.Buchholtz
      
Beiträge: 612
WIN 2000, WIN XP, Mac OS X
D7 Enterprise, XCode, Eclipse, Ruby On Rails
|
Verfasst: Mo 15.08.05 16:33
Jacko hat folgendes geschrieben: | Hallo,
ich bekomme in mein Programm SmallInt-Werte aus einer anderen Applikation. Leider sind das Obere und Untere Byte vertauscht.
Wie tausche ich diese Bytes
Danke im Voraus. |
Die Windows-Funktion ntohs in der Unit WinSock macht das.
Stefan
|
|
uall@ogc
      
Beiträge: 1826
Erhaltene Danke: 11
Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
|
Verfasst: Mo 15.08.05 16:37
Delphi-Quelltext 1: 2: 3: 4:
| function change(bla: smallint): smallint; asm ror ax, 8 end; |
_________________ wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
|
|
Jacko 
      
Beiträge: 20
|
Verfasst: Mo 15.08.05 17:11
| uall@ogc hat folgendes geschrieben: | Delphi-Quelltext 1: 2: 3: 4:
| function change(bla: smallint): smallint; asm ror ax, 8 end; | |
Bei diesem Beispiel gibt er mir 28724 raus, wenn ich 0(=bla) übergebe ???
warum ?
Moderiert von raziel: Quote- und Delphi-Tags hinzugefügt.
|
|
uall@ogc
      
Beiträge: 1826
Erhaltene Danke: 11
Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
|
Verfasst: Mo 15.08.05 17:15
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
| function change(zahl: smallint): smallint; asm ror ax, 8 end;
procedure TForm1.FormCreate(Sender: TObject); var bla: smallint; begin bla := 0; bla := change(bla); form1.caption := inttostr(bla); end; |
liefert bei mir einwandfreie ergebnisse oO
_________________ wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
|
|
Jacko 
      
Beiträge: 20
|
Verfasst: Di 16.08.05 12:29
Danke,
musste die Funktion ein wenig umstellen, da das Register 'D' und nicht 'A' die werte übernommen hat. 'A' gibt sie wieder zurück. (wieso? keine Ahnung).
function TFormMain.change(zahl: smallint): smallint;
asm
ror dx, 8
mov ax,dx
end;
|
|