|
发表于 2020-6-20 11:45:01
|
显示全部楼层
function ConvertInteger(Source, Len: Integer): String;
var
i: Integer;
begin
Result := '';
if Len > SizeOf(Source) then
Exit;
for i := 1 to Len do
begin
Result := Chr(Source and $FF) + Result;
Source := Source shr 8;
end;
end;
//将协议整数(网络字节顺序的多个字节)还原为整数
function RevertInteger(Source: String): Integer;
var
i, Len: Integer;
n: Int64;
begin
Source := Copy(Source, 1, SizeOf(Result));
Result := 0;
n := 0;
i := 1;
Len := Length(Source);
while i <= Length(Source) do
begin
n := n shl 8 + Ord(Source[i]);
Inc(i);
end;
if n > Power($100, Len) / 2 - 1 then
n := n - Floor(Power($100, Len));
Result := n;
end;
//LZ要这个干嘛???这样转换很容易出界的 |
|