![]() |
AW: Typecasting eines Arrays von Byte und Schreiben in verschiedene Variablen in Delp
Swap
und in der System-Unit versteckt sich auch etwas (intern), wenn ich mich nicht irre. (wegen MacOS, was andersrum ist/war/oderso) |
AW: Typecasting eines Arrays von Byte und Schreiben in verschiedene Variablen in Delp
Zitat:
Delphi-Quellcode:
(aus meiner
///<summary>
/// returns a 16 bit in reversed byte order, e.g. $1234 => $3412) /// aka converts intel (little endian) to motorola (big endian) byte order format /// (This is just an alias for system.swap for consistency with Swap32.) ///</summary function Swap16(_Value: Word): Word; ///<summary> /// returns a 32 bit value in reversed byte order e.g. $12345678 -> $78563412 /// aka converts intel (little endian) to motorola (big endian) byte order format </summary> function Swap32(_Value: LongWord): LongWord; function Swap32pas(_Value: LongWord): LongWord; function Swap16(_Value: Word): Word; {$IFDEF SUPPORTS_INLINE} inline; {$ENDIF} begin Result := swap(_Value); end; // alternative implementation based on https://stackoverflow.com/a/3065619/49925 //function Swap16(Value: smallint): smallint; register; //asm // rol ax, 8 //end; function Swap32(_Value: LongWord): LongWord; asm bswap eax end; function Swap32pas(_Value: LongWord): LongWord; begin Result := ((_Value shr 24) and $FF) + (((_Value shr 16) and $FF) shl 8) + (((_Value shr 8) and $FF) shl 16) + ((_Value and $FF) shl 24); end; ![]() Die Konvertierung ist symmetrisch, d.h. auch wenn die Beschreibung sagt Little Endian -> Big Endian, kann man sie auch für Big Endia -> Little Endian verwenden. Swap32pas ist lediglich eine Pascal-Implementation von Swap32, also ohne Assembler-Code. Das Ergebnis ist identisch. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:20 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