(* Collection of code snippets by Arne Vajhøj *)
(* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) *)
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function CharToBin(Value : Char): String;

var
  tmp,i : Integer;

begin
  tmp := Ord(value);
  Result := '';
  for i := 1 to 8 do begin
    Result := Chr(48 + (tmp and 1)) + Result;
    tmp := tmp shr 1;
  end;
end;

function StringToBin(Value : String) : String;

var
  i : Integer;

begin
  Result := '';
  for i := 1 to length(Value) do begin
    Result := Result + CharToBin(Value[i]);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);

begin
  Edit2.Text := StringToBin(Edit1.Text);
end;

end.
