且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将大端数字转换为本地数字delphi

更新时间:2023-02-10 17:57:35

安德烈亚斯(Andreas)的回答是一个很好的例子,说明如何以纯Pascal进行操作,但是它仍然有点尴尬,就像C ++代码一样。实际上,这可以在单个汇编指令中完成,尽管取决于您使用的是32位还是16位整数:

Andreas's answer is a pretty good example of how to do it in pure pascal, but it still looks kinda awkward, just like the C++ code. This can actually be done in a single assembly instruction, though which one depends on whether you're using 32-bit or 16-bit integers:

function SwapEndian32(Value: integer): integer; register;
asm
  bswap eax
end;

function SwapEndian16(Value: smallint): smallint; register;
asm
  rol   ax, 8
end;