如: 定义了一个 a: Integer数.
如何在表单程序中, 把a数的高字节和低字节转化过来?我有使用了Swap函数来做, 但是提示如下信息:
Statement expected, but expression of type 'Integer' found.
????????????????????????????????
如何在表单程序中, 把a数的高字节和低字节转化过来?我有使用了Swap函数来做, 但是提示如下信息:
Statement expected, but expression of type 'Integer' found.
????????????????????????????????
var
i : Integer;
pA, pB: PByte;
begin
pA := @Value;
pB := @Result;
inc(pA, SizeOf(LongWord) - 1);
for i := 1 to SizeOf(LongWord) do
begin
pB^ := pA^;
dec(pA);
inc(pB);
end;
end;
有要的是Integer的类型, 不是LongWord类型!
至于看不懂,那只能介绍你先学习一下指针操作了。
function Swap32(const Input:Integer):Integer;
asm
BSWAP eax {486+}
end;
begin
Result := (Value shr 24) or (Value shl 24) or (Value and $00ffff00);
end;
x:= i shr 16 + (i and $ff) shl 16 我有点明白你的意思, 但是Integer是在delphi中占4个字节!
$ff ???? 这样对吗?
((x and $ffff) shr 16) or ((x shl 16) and $ffff)2. 第一字节和第四字节调换
((x and $ff) shr 24) or ((x shl 24) and $ff) and (x and $ffff00)3. 字节序逆转(“一,二,三,四”转换为“四,三,二,一”)
可以使用我上面的方法,那个只是一条汇编指令,效率比位操作要高得多