![]() |
Delphi-Version: 2005
HI und LO liefern falsche Werte
Was mache ich da falsch?
Delphi-Quellcode:
Bei 2345 bekomme ich als 'HI' die Zahl 9 und bei 'LO' die Zahl 41 ?!?
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState); var int:Integer; begin if Key = VK_Return then begin int:=strtoint(Edit1.text); Label4.Caption:= 'ganze Zahl: '+ inttostr(int); Label2.Caption:= 'HI: '+ inttostr(hi(int)); Label3.Caption:= 'LO: '+ inttostr(lo(int)); end; end; Sollte da nicht HI 23 und LO 45 rauskommen? |
AW: HI und LO liefern falsche Werte
Nein, denn 9 * 256 = 2304 + 41 = 2345
|
AW: HI und LO liefern falsche Werte
Zitat:
Habe diesen Code gefunden, der da was ganz anderes ausgibt...
Delphi-Quellcode:
Show full unit code
Example code : Illustrate Ho and Lo functions
var i : Integer; begin i := $2345; // $2345 hex : $23 hi byte, $45 lo byte ShowMessage(Format('Integer = $%x', [i])); ShowMessage(Format('Hi byte = $%x', [Hi(i)])); ShowMessage(Format('Lo byte = $%x', [Lo(i)])); end; Integer = $2345 Hi byte = $23 Lo byte = $45 Hm, die Hi-LO Functionen funktionieren da wohl auch nur mit Word (0..65535) und nicht mit Integer(...-3-2-1 0 1 2 3...)? Gut für meinen Zweck mache ich mir einen:
Delphi-Quellcode:
Eigentlich könnte man da auch statt 'ShortInt' Integer verwenden.
Type
TMyshrtInt = Record h,l : shortint end; Delphi 2005 und die CPU nutzt doch die vollen 32Bit. Und Shortint bringt wohl keinen Schnelligkeitsvorteil. |
AW: HI und LO liefern falsche Werte
Doch die sollten auch mit Integer funktionieren. Sie gehen aber Standardmässig von Dezimalzahlen aus und nicht von Zahlen in Hex.
Delphi-Quellcode:
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState); var int:Integer; begin if Key = VK_Return then begin int:=strtoint('$'+Edit1.text); Label4.Caption:= 'ganze Zahl: '+ inttostr(int); Label2.Caption:= 'HI: '+ inttostr(hi(int)); Label3.Caption:= 'LO: '+ inttostr(lo(int)); end; |
AW: HI und LO liefern falsche Werte
Zitat:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 08:59 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