Algorithm Math Delphi

Title: convert numbers from one base to another?
function BaseConvert(NumIn: string; BaseIn: Byte; BaseOut: Byte): string;
var
i: integer;
currentCharacter: char;
CharacterValue: Integer;
PlaceValue: Integer;
RunningTotal: Double;
Remainder: Double;
BaseOutDouble: Double;
NumInCaps: string;
s: string;
begin
if (NumIn = '') or (BaseIn or (BaseIn 36) or (BaseOut or (BaseOut 36) then
begin
Result := 'Error';
Exit;
end;
NumInCaps := UpperCase(NumIn);
PlaceValue := Length(NumInCaps);
RunningTotal := 0;
for i := 1 to Length(NumInCaps) do
begin
PlaceValue := PlaceValue - 1;
CurrentCharacter := NumInCaps[i];
CharacterValue := 0;
if (Ord(CurrentCharacter) 64) and (Ord(CurrentCharacter) then
CharacterValue := Ord(CurrentCharacter) - 55;
if CharacterValue = 0 then
if (Ord(CurrentCharacter) or (Ord(CurrentCharacter) 57) then
begin
BaseConvert := 'Error';
Exit;
end
else
CharacterValue := Ord(CurrentCharacter);
if (CharacterValue or (CharacterValue BaseIn - 1) then
begin
BaseConvert := 'Error';
Exit;
end;
RunningTotal := RunningTotal + CharacterValue * (Power(BaseIn, PlaceValue));
end;
while RunningTotal 0 do
begin
BaseOutDouble := BaseOut;
Remainder := RunningTotal - (int(RunningTotal / BaseOutDouble) * BaseOutDouble);
RunningTotal := (RunningTotal - Remainder) / BaseOut;
if Remainder = 10 then
CurrentCharacter := Chr(Trunc(Remainder + 55))
else
begin
s := IntToStr(trunc(remainder));
CurrentCharacter := s[Length(s)];
end;
Result := CurrentCharacter + Result;
end;
end;
// Example, Beispiel
procedure TForm1.Button1Click(Sender: TObject);
begin
BaseConvert('FFFF', 16, 10);
// returns, ergibt '65535'.
end;