![]() |
LowByte und Highbyte beschreiben
Hallo zusammen,
ich habe folgende Situation: Auf einen SmallInt soll ich einmal ein Highbyte schreiben und einmal ein Lowbyte. LowByte: SmallInt := MeinWert and $0000FFFF HighByte: SmallInt := MeinWert shr 16 Das geht auch soweit aber wie ist es möglich, dass wenn ich das Highbye beschreiben will auf mein SmallInt, dass ich das vorhandene LowByte nicht mit überschreibe (es soll also vorhanden bleiben). Andersrum genauso. Wenn ich das LowByte beschreibe, soll das Highbyte nicht mit beschrieben werden. Ich hoffe ihr könnt mir da helfen... Danke MFG Alex |
Re: LowByte und Highbyte beschreiben
am besten etwa so:
Delphi-Quellcode:
Damit hast du einen neuen Typ, den du verwenden kannst.
type TmySmallint= {packed} record
case Boolean of True: (SI:smallint); False: (LoByte:byte; HiByte:Byte); end; Edit: btw.: Was ist denn bei dir Smallint? Mit (MeinWert and $0000FFFF) besetzt du den gesamten Smallint und nicht nur das LoByte. |
Re: LowByte und Highbyte beschreiben
Mal aus dem Kopf:
Delphi-Quellcode:
P.S.: Sirius hat übrigens Recht, bei $0000FFFF sind bereits alle Bits gesetzt.
procedure SetLowByte(var sInt: SmallInt; const b: Byte);
begin sInt := sInt or b; end; procedure SetHighByte(var sInt: SmallInt; const b: Byte); begin sInt := sInt or (b shl 8); end; |
Re: LowByte und Highbyte beschreiben
Oder
Delphi-Quellcode:
uses
SysUtils; //... WordRec(YourSmallint).Lo := 1; WordRec(YourSmallint).Hi := 2; |
Re: LowByte und Highbyte beschreiben
Zitat:
|
Re: LowByte und Highbyte beschreiben
Zitat:
|
Re: LowByte und Highbyte beschreiben
Zitat:
|
Re: LowByte und Highbyte beschreiben
OK, da hast Du Recht.
|
Re: LowByte und Highbyte beschreiben
Delphi-Quellcode:
procedure SetLowByte(var sInt: SmallInt; const b: Byte);
begin sInt := (sInt and $FF00) or b; end; procedure SetHighByte(var sInt: SmallInt; const b: Byte); begin sInt := (sInt and $FF) or (b shl 8); end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:24 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz