![]() |
![]() |
![]() |
![]() |
![]() |
FTP | ![]() |
![]() |
CCD | ![]() |
![]() |
Buscar | ![]() |
![]() |
Trucos | ![]() |
![]() |
Trabajo | ![]() |
![]() |
Foros | ![]() |
|
Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Temas de Hoy |
![]() |
|
Herramientas | Buscar en Tema | Desplegado |
#1
|
|||
|
|||
![]() Estoy haciendo un programa para con vertir numeros de hexadecimal a decimal y estoy haciendo lo siguiente:
implementation {$R *.dfm} function BaseNADec(num : string; n : byte) : integer; var i : integer; aux : string; begin // Solo hasta la 'o' = como máximo base 20... suficiente ¿no? aux:='0123456789ABCDEF'; result:=0; for i:=1 to length(num) do result:=result*n+pos(upcase(num[i]),aux)-1; end; // De base 16 (hexadecimal) a base 10 (decimal) function HexADec(num : string) : integer; begin result:=BaseNADec(num,16); end; procedure TForm1.Button1Click(Sender: TObject); var x : integer; v : string; begin x:=256; v := HexADec(x); edit2.Text := v; end; end. Pero no lo puedo ejecutar porque me dice que son inconpatible integer con string ayudenme por favor a encontrar el error por favor ya que soy novato en esto. Gracias. |
#2
|
||||
|
||||
Código:
procedure TForm1.Button1Click(Sender: TObject); var x : integer; v : string; begin x:=256; v := IntToStr(HexADec(x)); edit2.Text := v; end; Un Saludo.
__________________
Guía de Estilo de los Foros Cita:
![]() |
#3
|
||||
|
||||
Aquí tienes un truco para pasar un número de Hexadecimal a Decimal.
Código:
procedure TForm1.Button1Click(Sender: TObject); Var MiHexa:String; Hexa2Dec:Integer; begin MiHexa:='FFFF'; Hexa2Dec:= StrToInt( '$'+MiHexa); ShowMessage(IntToStr(Hexa2Dec)); end;
__________________
Guía de Estilo de los Foros Cita:
![]() |
#4
|
|||
|
|||
![]() hice las siguientes modificaiones al codigo:
[color=red]implementation {$R *.dfm} function BaseNADec(num : string; n : byte) : integer; var i : integer; aux : string; begin // Solo hasta la 'o' = como máximo base 20... suficiente ¿no? aux:='0123456789ABCDEF'; result:=0; for i:=1 to length(num) do result:=result*n+pos(upcase(num[i]),aux)-1; end; // De base 16 (hexadecimal) a base 10 (decimal) function HexADec(num : string) : integer; begin result:=BaseNADec(num,16); end; // De base 2 (binario) a base 10 (decimal) function BinADec(num : string) : integer; begin result:=BaseNADec(num,2); end; // De base 8 (octal) a base 10 (decimal) function OctADec(num : string) : integer; begin result:=BaseNADec(num,8); end; procedure TForm1.Button1Click(Sender: TObject); Var M:String; HexADec,BinADec,OctADec:Integer; begin if combobox1.Text:= 'Binario' and combobox2.Text:= 'Decimal' then begin M:=edit1.text; BinADec:= StrToInt( '$'+M); edit2.Text:= IntToStr(BinADec); else begin if combobox1.Text:= 'Hexadecimal' and combobox2.Text:= 'Decimal' then begin M:=edit1.text; HexADec:= StrToInt( '$'+M); edit2.Text:= IntToStr(HexADec); end; else begin if combobox1.Text:= 'Octal' and combobox2.Text:= 'Decimal' then begin M:=edit1.text; OctADec:= StrToInt( '$'+M); edit2.Text:= IntToStr(OctADec); end; end; end; end;COLOR] Pero me da los siguientes errores: [Error] Unit1.pas(68): Incompatible types: 'String' and 'procedure, untyped pointer or untyped parameter' [Error] Unit1.pas(73): ';' not allowed before 'ELSE' No es que quiera abusar de ustedes pero comprendame soy bastante inexperto con esto pero dos o tres indicaciones y ahi solo. Gracias |
#5
|
|||
|
|||
Hola RedVenom:
Los errores que te dan son errores de sintaxis, por ejemplo Cita:
Cita:
Delante de un else nunca puede haber un punto y coma ';' |
![]() |
|
|
![]() |
|