5,392
社区成员
发帖
与我相关
我的任务
分享
//这段代码是直接根据你的C代码翻译的
procedure convertToLittleEndian(var int : DWORD);
begin
int := ((int and $ff000000) SHR 24)
or ((int and $00ff0000) SHR 8)
or ((int and $0000ff00) SHL 8)
or ((int and $000000ff) SHL 24);
end;
//这个代码就不说了,上面的函数搞半天,其实就是一行指令.
function convertToLittleEndian2(dw : DWORD) : DWORD;
asm
BSWAP EAX
end;
procedure TForm1.FormCreate(Sender: TObject);
var
n1 , n2 : DWORD;
begin
n1 := $12345678;
n2 := $12345678;
convertToLittleEndian(n1);
n2 := convertToLittleEndian2(n2);
if n1=n2 then
Caption := 'OK';
题外话,楼主用这个函数转换,其实不是很得体procedure convertToLittleEndian(var i32:Longword)
var
p,p2:pbyte;
b:byte;
begin
p:=pbyte(@i32);
p2:=p; inc(p2,4);
b:=p^; p^:=p2^; p2^:=b;
inc(p); p2:=p; inc(p2);
b:=p^; p^:=p2^; p2^:=b;
end;