Delphi Tips&Tricks News   Tips   .NET Software   VCL Software   Search   Contacts
Ultimate Pack Special Offer!


Share this page

Follow us
LinkedIn Blogspot Twitter Facebook

Related products
Ultimate Pack  hot!
iGrid Plotter  new!
Image Editor
Runtime Fusion
Form Designer
Object Inspector
Print Suite Pro
Commented Image
Delphi Toys
WinDowse
Delphi Bonus
TMS Scripter Studio
Form Designer VB
Form Designer .NET
Print Suite .NET
Gradient Controls .NET  new!

Related links
Win32.hlp online version
MegaDetailed.NET
Delphi to C#

Special
Free Software Promotion
Offers for Resellers

Hobby projects
cdtrrracks.com
books.storrre.com
in3steps.com
sovietphillumeny.com

Convert octal to binary - Mathematics - Tips & Tricks - Greatis Delphi Pages

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;
Related topics
Convert binary to octal
Convert binary to hexadecimal
Convert hexadecimal to binary
Convert octal to decimal
Convert decimals to binary
Convert decimals to hexadecimals
Convert hexadecimals to decimals
Convert binary to decimals

For more
Delphi Help

Download source