procedure TForm2.Button20Click(Sender: TObject);
var
a, b, c, d, e: DWord;
function ReverseD0(i: DWord): DWord; //32 bit
asm
bswap eax
end;
function ReverseD1(i: DWord): DWord;
begin
Result := ((i and $FF) shl 24) or
(((i shr 8) and $FF) shl 16) or
(((i shr 16) and $FF) shl 8) or
(((i shr 24) and $FF));
end;
function ReverseD2(i: DWord): DWord;
var
c, d: LongRec;
begin
c := LongRec(i);
d := Longrec(Result);
d.Bytes[0] := c.Bytes[3];
d.Bytes[1] := c.Bytes[2];
d.Bytes[2] := c.Bytes[1];
d.Bytes[3] := c.Bytes[0];
end;
function ReverseD3(i: DWord): DWord;
var
c: Integer;
begin
for c := 0 to 3 do
PByteArray(@Result)[c] := PByteArray(@i)[3-c];
end;
begin
a := $AABBCCDD;
b := ReverseD0(a);
c := ReverseD1(a);
d := ReverseD2(a);
e := ReverseD3(a);
Memo1.Lines.Add(Format('%x %x %x %x %x', [a, b, c, d, e]));
end;
>>> AABBCCDD DDCCBBAA DDCCBBAA DDCCBBAA DDCCBBAA
program Reverse;
var
hexValue, x, r: Int64;
//***********************************************************************
//Не знаю как с этим компилятором вывести hex
//для вывода эта функция
function IntToHex(Value: Int64): string;
var pos:integer;
HexChars:string;
Result:string;
begin
Result:='';
while Value>0 do
begin
HexChars := '0123456789ABCDEF';
pos:=Value mod $10;
Result := HexChars[pos + 1] + Result;
Value:=Value div $10;
end;
IntToHex:= Result;
end;
//************************************************************************
// программа реверс
begin
hexValue := $2300FFC0;// Оставим исходное число для вывода, по желанию
x:= hexValue;
r := 0;
while x > 0 do
begin
r := r * $100 + (x mod $100); // остаток от деления прибавляем к перевертышу
x := x div $100;
end;
writeln('hexValue ',IntToHex(hexValue));
writeln('Reverse ',IntToHex(r));
end.
几种可能的方法:
“十六进制”是人类表示数字的方式,我假设您只有一个数字,而不是字符串。
https://onecompiler.com/pascal/42xjbtcsm
也许 C 程序会帮助你
(
uint32_t
这是一个 32 位大小的无符号整数类型)