![]() |
int32_t , int16_t in Delphi, Function nach Delphi übersetzen
wie würde man diesen Code in Delphi übersetzen
Delphi-Quellcode:
inline void gds (int32_t &i)
{ // ...... // swap required char x; char *d = (char *)&i; x = d[0]; d[0] = d[3]; d[3] = x; x = d[1]; d[1] = d[2]; d[2] = x; // ...... // other action i = (int32_t (((unsigned char *)&i) [0]) << 24) | (int32_t (((unsigned char *)&i) [1]) << 16) | (int32_t (((unsigned char *)&i) [2]) << 8) | int32_t (((unsigned char *)&i) [3]); #endif } |
AW: int32_t , int16_t in Delphi, Function nach Delphi übersetzen
Da hast du ja wilden Code gefunden. Als erstes werden die Bytes von i umgedreht, wie bei einer Endianess-Konvertierung.
Der andere Abschnitt sieht ähnlich aus, hier wird wird aus dem Byte an der niedrigsten Adresse das signifikanteste Byte in einem 32bit IntegeR, usw... Könnte eine Konvertierung von Big-Endian zur Endianess des Sytems sein. |
AW: int32_t , int16_t in Delphi, Function nach Delphi übersetzen
Ich glaube, man könnte es so übersetzen:
Delphi-Quellcode:
Ungetestet.
function gds(i: LongInt): LongInt; inline;
var d: array[0..3] of Byte absolute i; x: Byte; begin // ...... // swap required x := d[0]; d[0] := d[3]; d[3] := x; x := d[1]; d[1] := d[2]; d[2] := x; // ...... // other action i := (Int32(d[0]) shl 24) or (Int32(d[1]) shl 16) or (Int32(d[2]) shl 8) or (Int32(d[3])); {$endif} end; |
AW: int32_t , int16_t in Delphi, Function nach Delphi übersetzen
Da fehlt ein #IF zum #ENDIF :stupid:
Und ja, da war jemand bissl wirr im Kopf und hat die "selbe" Endianess-Konvertierung auf zwei Weisen umgesetzt.
Delphi-Quellcode:
OHNE das "Heimliche" in den ... hebt sich das Gegenseitig auf und es kommt nix bei raus
procedure gds(var i: LongInt); inline;
begin // swap required i := ByteSwap(i); // sowas ähnliches, wie System.Swap // ...... // other action i := ByteSwap(i); end;
Delphi-Quellcode:
procedure gds(var i: LongInt); inline;
begin //i := ByteSwap(i); //i := ByteSwap(i); end; |
AW: int32_t , int16_t in Delphi, Function nach Delphi übersetzen
Bytes swappen <asm>
Aus ( ![]()
Code:
HTH!
function SwapDWord(DW: DWord): DWord;
asm {$IFDEF CPUX64} MOV EAX, ECX {$ENDIF CPUX64} BSWAP EAX end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:04 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 by Thomas Breitkreuz