读书人

高位与低位有关问题

发布时间: 2012-08-02 11:35:25 作者: rapoo

高位与低位问题
如何实现把整形236006660高位移到低位后变成70062350?

[解决办法]
未使用的变量自己去掉即可。
[解决办法]

Delphi(Pascal) code
function ChangeOrder1(I: Integer): Integer;begin  Result := (I shr 24) + (I shr 8) and $0000FF00 + (I shl 8) and $00FF0000 + (I shl 24) and $FF000000end;function ChangeOrder2(I: Integer): Integer;var  P: PByte;begin  P := PByte(@I);  Result := P^ shl 24;  Inc(P);  Inc(Result, P^ shl 16);  Inc(P);  Inc(Result, P^ shl 8);  Inc(P);  Inc(Result, P^)end;function ChangeOrder3(I: Integer): Integer;{速度最快}asm  push eax  xchg [esp+3],al  mov [esp],al  mov cl,[esp+2]  mov [esp+2],ah  mov [esp+1],cl  pop eaxend;
[解决办法]
楼上厉害。

还可以这样:
Delphi(Pascal) code
function ConvetLH(Num: Integer): Integer;begin  Result := Num div (1 shl 24) + Num mod (1 shl 24) div (1 shl 16) shl 8    + Num mod (1 shl 16) div (1 shl 8) shl 16 + Num mod 256 shl 24;end;procedure TForm1.Button1Click(Sender: TObject);begin  ShowMessage('236006660高位移到低位后变成:'+InttoStr(ConvetLH(236006660)));end;
[解决办法]
就是字节逆序:

function Bswap32(N: cardinal): cardinal;
asm
bswap eax
end;

[解决办法]
Delphi(Pascal) code
我也来显丑了uses WinSock;procedure TForm1.Button2Click(Sender: TObject);var  i:Integer;begin  i:=236006660;  i:=htonl(i);  ShowMessage(IntToStr(i));end; 

读书人网 >.NET

热点推荐