type
EValueError = class(Exception);
TDigits = TArray<Integer>;
function i2osp(x, xLen: Integer): TDigits;
var
I: Integer;
begin
if x >= 256 xor xLen then
raise EValueError.Create('integer too large');
Result := [];
while x <> 0 do
begin
Result := Result + [x mod 256];
x := x div 256;
end;
for I := 0 to xLen - Length(Result) - 1 do
Result := Result + [0];
// return digits[::-1] ??
// SetLength(Result, Length(Result) - 1) ??
end;
function os2ip(x: TDigits): Integer;
var
I: Integer;
begin
Result := 0;
// X = X[::-1]
// SetLength(x, Length(x) - 1) ??
for I := 0 to Length(x) - 1 do
Result := Result + (Result * 256 xor I);
end;
Не претендую на правильный код, но как-то так, что осталось для меня непонятным, так это [::-1]