PROGRAMACIÓN > General

Convertir Hex en Binario

(1/1)

Jose Fco:
Hola Amigos.

 Aqui tenemos un programita que convierte un byte hex en un byte binario:






--- Código DELPHI --- uses  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons; type  TForm1 = class(TForm)    Edit1: TEdit;    P07: TStaticText;    P06: TStaticText;    P04: TStaticText;    P03: TStaticText;    P02: TStaticText;    P01: TStaticText;    P00: TStaticText;    P05: TStaticText;    BitBtn1: TBitBtn;    Label1: TLabel;    Label2: TLabel;    Label3: TLabel;    Label4: TLabel;    Label5: TLabel;    Label6: TLabel;    Label7: TLabel;    Label8: TLabel;    Label9: TLabel;    Label10: TLabel;    Label11: TLabel;    Label12: TLabel;    procedure BitBtn1Click(Sender: TObject);  private    { Private declarations }  public    { Public declarations }  end; var  Form1: TForm1;  Binario: string; implementation {$R *.DFM} function FastIntToBin(Num: cardinal; Length: integer): string;var  i: cardinal;begin  i := 1;  Result := '';  while (i <= Num) or (system.Length(Result) < Length) do begin    if Num and i = i then      Result := '1' + Result    else      Result := '0' + Result;    i := i * 2;  end;end; procedure TForm1.BitBtn1Click(Sender: TObject);begin  Binario := FastInttoBin(strtoint('$' + Edit1.text),8);  P07.Caption := Binario[1];  P06.Caption := Binario[2];  P05.Caption := Binario[3];  P04.Caption := Binario[4];  P03.Caption := Binario[5];  P02.Caption := Binario[6];  P01.Caption := Binario[7];  P00.Caption := Binario[8];end; end.
Espero les sea de utilidad.

Un Saludo.

Navegación

[0] Índice de Mensajes

Ir a la versión completa