SPECIAL OFFER        Order and save right now!
20% off with the 729824315 dicscount code for Ultimate Pack and any another product for Delphi from Greatis Programming!

⤷ Convert octal to binary

Use OctToBin function to convert number in octal format to binary format.

function OctToBin(OctStr: string): string;

  function DecToBinStr(N: Integer): string;
  var
    S: string;
    i: Integer;
  begin
    if N<>0 then
      for i:=1 to SizeOf(N)*8 do
      begin
        if N<0 then
          S:=S+'1'
        else
          S:=S+'0';
        N:=N shl 1;
      end
    else
      S:='0';
    Delete(S, 1, Pos('1', S)-1);
    case Length(S) mod 3 of
      1: S:='00'+S;
      2: S:='0'+S;
    end;
    Result:=S;
  end;

var
  i: Integer;
begin
  Result:='';
  for i:=1 to Length(OctStr) do
  begin
    if not (OctStr[i] in ['0','1','2','3','4','5','6','7']) then
    begin
      ShowMessage('This is not octal number');
      Result:='';
      Break;
    end
    else
      Result:=Result+DecToBinStr(StrToInt(OctStr[i]));
      while (Result[1]='0')and(Length(Result)>1) do
        Delete(Result, 1, 1);
  end;
end;
More for developers
Databases for Amazon Associates
Amazon Categories
Amazon Nodes