//无限进制转换:一位高人的程序
//pas 
unit DigitUnit; 
 
interface 
 
uses 
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 
  StdCtrls, Spin; 
 
type 
  TForm1 = class(TForm) 
    Button1: TButton; 
    Edit1: TEdit; 
    Edit2: TEdit; 
    Button2: TButton; 
    SpinEdit1: TSpinEdit; 
    procedure Button1Click(Sender: TObject); 
    procedure Button2Click(Sender: TObject); 
  private 
    { Private declarations } 
  public 
    { Public declarations } 
  end; 
 
var 
  Form1: TForm1; 
 
implementation 
 
{$R *.DFM} 
 
function Power(Base, Exponent: Integer): Integer; 
var 
  I: Integer; 
begin 
  Result := 1; 
  for I := 1 to Exponent do 
    Result := Result * Base; 
end; { Power } 
 
const 
  cScaleChar = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; 
 
function DigitToInt(mScale: Byte; mDigit: string): Integer; 
var 
  I, L: Integer; 
begin 
  Result := 0; 
  L := Length(mDigit); 
  for I := L downto 1 do 
    Result := Result + Pred(Pos(mDigit[I], cScaleChar)) * Power(mScale, L - I); 
end; { DigitToInt } 
 
function IntToDigit(mScale: Byte; mInt: Integer): string; 
var 
  I, J: Integer; 
begin 
  Result := ''; 
  I := mInt; 
  while (I >= mScale) do begin 
    J := I mod mScale; 
    Result := Copy(cScaleChar, Succ(J), 1) + Result; 
    I := I div mScale; 
  end; 
  Result := Copy(cScaleChar, Succ(I), 1) + Result; 
end; { IntToDigit } 
 
procedure TForm1.Button1Click(Sender: TObject); 
begin 
  Edit2.Text := IntToStr(DigitToInt(SpinEdit1.Value, Edit1.Text)); 
end; 
 
procedure TForm1.Button2Click(Sender: TObject); 
begin 
  Edit1.Text := IntToDigit(SpinEdit1.Value, StrToIntDef(Edit2.Text, 0)); 
end; 
 
end. 
 
//dfm 
object Form1: TForm1 
  Left = 192 
  Top = 107 
  Width = 409 
  Height = 97 
  Caption = 'Form1' 
  Color = clBtnFace 
  Font.Charset = DEFAULT_CHARSET 
  Font.Color = clWindowText 
  Font.Height = -11 
  Font.Name = 'MS Sans Serif' 
  Font.Style = [] 
  OldCreateOrder = False 
  PixelsPerInch = 96 
  TextHeight = 13 
  object Button1: TButton 
    Left = 184 
    Top = 32 
    Width = 75 
    Height = 25 
    Caption = 'Button1' 
    TabOrder = 0 
    OnClick = Button1Click 
  end 
  object Edit1: TEdit 
    Left = 136 
    Top = 8 
    Width = 121 
    Height = 21 
    TabOrder = 1 
    Text = 'Edit1' 
  end 
  object Edit2: TEdit 
    Left = 272 
    Top = 8 
    Width = 121 
    Height = 21 
    TabOrder = 2 
    Text = 'Edit2' 
  end 
  object Button2: TButton 
    Left = 272 
    Top = 32 
    Width = 75 
    Height = 25 
    Caption = 'Button2' 
    TabOrder = 3 
    OnClick = Button2Click 
  end 
  object SpinEdit1: TSpinEdit 
    Left = 8 
    Top = 8 
    Width = 121 
    Height = 22 
    MaxValue = 255 
    MinValue = 2 
    TabOrder = 4 
    Value = 0 
  end 
end