Delphi Tips&Tricks News   Tips   .NET Software   VCL Software   Search   Contacts
Ultimate Pack - special offer!

Ultimate Pack  hot!
Image Editor  new!
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

...get more...
for Delphi.NET, C#, VB.NET
for Delphi VCL, BCB 3-6

WinAPI Online
Unix Manual Pages
MegaDetailed.NET
in3steps.com
cdtrrracks.com new!

Blogspot  greatis.blogspot.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