Ir al contenido


Convertir Hex en Binario


  • Por favor identifícate para responder
No hay respuestas en este tema

#1 Guest_Jose Fco_*

Guest_Jose Fco_*
  • Visitante

Escrito 01 noviembre 2008 - 06:08

Hola Amigos.

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

Imagen Enviada

Imagen Enviada



delphi
  1. uses
  2.   Windows, Messages, SysUtils, Classes, Graphics, Controls,
  3. Forms, Dialogs, StdCtrls, Buttons;
  4.  
  5. type
  6.   TForm1 = class(TForm)
  7.     Edit1: TEdit;
  8.     P07: TStaticText;
  9.     P06: TStaticText;
  10.     P04: TStaticText;
  11.     P03: TStaticText;
  12.     P02: TStaticText;
  13.     P01: TStaticText;
  14.     P00: TStaticText;
  15.     P05: TStaticText;
  16.     BitBtn1: TBitBtn;
  17.     Label1: TLabel;
  18.     Label2: TLabel;
  19.     Label3: TLabel;
  20.     Label4: TLabel;
  21.     Label5: TLabel;
  22.     Label6: TLabel;
  23.     Label7: TLabel;
  24.     Label8: TLabel;
  25.     Label9: TLabel;
  26.     Label10: TLabel;
  27.     Label11: TLabel;
  28.     Label12: TLabel;
  29.     procedure BitBtn1Click(Sender: TObject);
  30.   private
  31.     { Private declarations }
  32.   public
  33.     { Public declarations }
  34.   end;
  35.  
  36. var
  37.   Form1: TForm1;
  38.   Binario: string;
  39.  
  40. implementation
  41.  
  42. {$R *.DFM}
  43.  
  44. function FastIntToBin(Num: cardinal; Length: integer): string;
  45. var
  46.   i: cardinal;
  47. begin
  48.   i := 1;
  49.   Result := '';
  50.   while (i <= Num) or (system.Length(Result) < Length) do begin
  51.     if Num and i = i then
  52.       Result := '1' + Result
  53.     else
  54.       Result := '0' + Result;
  55.     i := i * 2;
  56.   end;
  57. end;
  58.  
  59. procedure TForm1.BitBtn1Click(Sender: TObject);
  60. begin
  61.   Binario := FastInttoBin(strtoint('$' + Edit1.text),8);
  62.   P07.Caption := Binario[1];
  63.   P06.Caption := Binario[2];
  64.   P05.Caption := Binario[3];
  65.   P04.Caption := Binario[4];
  66.   P03.Caption := Binario[5];
  67.   P02.Caption := Binario[6];
  68.   P01.Caption := Binario[7];
  69.   P00.Caption := Binario[8];
  70. end;
  71.  
  72. end.



Espero les sea de utilidad.

Un Saludo.




IP.Board spam blocked by CleanTalk.