10 <-> 2 转换
function IntToBin(i: longint): string;
var
quotient: integer;
remainder: string;
begin
if i < 0 then Exit;
quotient := i div 2;
while quotient > 0 do
begin
remainder := IntToStr(i mod 2) + remainder;
i := quotient;
quotient := i div 2;
end;
remainder := IntToStr(i mod 2) + remainder;
Result := remainder;
end;
function BinToInt(bin: pChar): extended;
var
len, i: integer;
begin
Result := 0;
if bin <> nil then
begin
len := Length(bin);
i := len;
while bin^ <> #0 do
begin
if (ord(bin^) > 57) or (ord(bin^) < 48) then
begin
Result := 0;
Exit;
end;
i := i - 1;
Result := Result + StrToInt(bin^) * IntPower(2, i);
inc(bin);
end;
end;
end;
function conver(const m,n:integer):string;
const
Table: array [0..19] of char = '0123456789ABCDEFGHIJ';
var
a,b:integer;
begin
Result:='';
a:=m;
b:=n;
repeat
result:=table[a mod b]+result;
a:=a div b;
until a=0;
end;