(* 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) *)
program bin;

{$APPTYPE CONSOLE}

uses
  SysUtils, Math;

function IntToBin(Value : Integer): String;

var
  tmp : Integer;
  digits : array [0..1] of char;

begin
  tmp := value;
  digits[0] := '0';
  digits[1] := '1';
  Result := '';
  while tmp > 0 do begin
    Result := digits[tmp and 1] + Result;
    tmp := tmp shr 1;
  end;
end;

function BinToInt(Value: String): LongInt;

var
  i, Size: Integer;

begin
  Result := 0;
  Size := Length(Value);
  for i := 1 to size do begin
    Result := Result shl 1;
    if Value[i] = '1' then begin
      Result := result + 1;
    end;
  end;
end;

begin
  writeln(IntToBin(7));
  writeln(IntToBin(12));
  writeln(BinToInt('111'));
  writeln(BinToInt('1100'));
end.
