unit IntXU;
interface
uses Math, Dialogs, SysUtils;
type
IntX = array of byte;
function add(a, b: IntX): IntX;
function IntXToStr(x: IntX): String;
function IntToIntX(x: Integer): IntX;
implementation
function add(a, b: IntX): IntX;
var i, uebertrag: Integer;
begin
uebertrag := 0;
setlength(Result, max(length(a), length(b)));
for i := 0 to max(length(a), length(b)) - 1 do
begin
Result[i] := 0;
if i < length(a) then Inc(Result[i], a[i]);
if i < length(b) then Inc(Result[i], b[i]);
Inc(Result[i], Uebertrag);
if Result[i] >= 10 then
begin
dec(Result[i], 10);
uebertrag := 1;
end
else uebertrag := 0;
end;
if uebertrag = 1 then
begin
setlength(Result, Length(Result)+1);
Result[Length(Result)-1] := 1;
end;
end;
function IntXToStr(x: IntX): String;
var i: Integer;
begin
SetLength(Result, Length(x));
for i := 0 to High(x) do
Result[i+1] := Char(Ord('0') + x[High(x)-i]);
end;
function IntToIntX(x: Integer): IntX;
var i: Integer; Stellen: Byte;
begin
if x < 0 then exit;
for i := 1 to 13 do
if x < power(10, i) then
begin
Stellen := i;
break;
end;
setlength(Result, Stellen);
for i := Stellen - 1 downto 0 do
begin
Result[i] := x div round(power(10, i));
x := x - Result[i] * round(power(10, i));
end;
end;
end.