Ver Mensaje Individual
  #4  
Antiguo 09-09-2011
justinesteban justinesteban is offline
Registrado
NULL
 
Registrado: sep 2011
Posts: 7
Reputación: 0
justinesteban Va por buen camino
si ya tengo las funciones de suma ponderada y divicion reiterada

Código Delphi [-]
type
  TForm1 = class(TForm)
    Edit1: TEdit;
    rgbases: TRadioGroup;
    Label1: TLabel;
    resul: TLabel;
    Label2: TLabel;
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    function sp(s:string; bp:integer):string;
    function dr(s:string; bl:integer):string;
    procedure rgbasesClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  case rgbases.ItemIndex of
  0: if not (key in ['1','0']) then
  key:=#0;
  1: if not (key in ['0'..'7']) then
  key:=#0;
  2: if not (key in ['0'..'9']) then
  key:=#0;
  3: if not (key in ['0'..'9','A'..'F']) then
  key:=#0;
  end;
end;

function tform1.sp(s:string; bp:integer):string;
var
  i:integer;
  ac:Extended;
  begin
    ac:=0;
    for i:=1 to length(s) do
      case s[i] of
        'A':ac:=ac+10*power(bp,length(s)-i);
        'B':ac:=ac+11*power(bp,length(s)-1);
        'C':ac:=ac+12*power(bp,length(s)-1);
        'D':ac:=ac+13*power(bp,length(s)-1);
        'E':ac:=ac+14*power(bp,length(s)-1);
        'F':ac:=ac+15*power(bp,length(s)-1);
      ELSE
        ac:=ac+strtoint(s[i])*power(bp,length(s)-i);
      end;
      result :=FloatTostr(ac);
    end;
function tform1.dr(s:string;bl:integer):string;
var
d,numero:integer;
resultado:string;
begin
  resultado:='';
  numero:=strtoint(s);
  while numero>0 do
  begin
    d:=numero mod bl;
    numero:=numero div bl;
      case d of
        10:resultado:='A'+ resultado;
        11:resultado:='B'+ resultado;
        12:resultado:='C'+ resultado;
        13:resultado:='D'+ resultado;
        14:resultado:='E'+ resultado;
        15:resultado:='F'+resultado;
      else
        resultado:=inttostr(d)+resultado;
      end;
      result:=resultado;
    end;
    end;


     



end;
end.
Imágenes Adjuntas
Tipo de Archivo: jpg Sin título.jpg (24,9 KB, 6 visitas)

Última edición por justinesteban fecha: 09-09-2011 a las 16:34:06.
Responder Con Cita