Delphi/CB
•  Greatis •  Security •  AppDatabase •  Utilities •  Visual Basic • .NET •  just4fun
Delphi / C++ Builder
Components, utilities and tips for Delphi and C++ Builder developers
Hot Offer
Save your money!
Featured
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

News Tips .NET Software VCL Software Partners  

Convert binary to octal
Use BinToOct function to convert number in binary format to octal format.

function BinToOct(BinStr: string): string;
var
  i: Integer;
  OctPart: Real;
  LastPart, OctStr: string;
  Error: Boolean;
begin
  Error:=False;
  OctStr:='';
  case Length(BinStr) mod 3 of
    1: BinStr:='00'+BinStr;
    2: BinStr:='0'+BinStr;
  end;

  while Length(BinStr)>0 do
  begin
    LastPart:=Copy(BinStr, Length(BinStr)-2, 3);
    Delete(BinStr, Length(BinStr)-2, 3);
    OctPart:=0;
    for i:=1 to 3 do
      if not (LastPart[i] in ['0', '1']) then
      begin
        ShowMessage('This is not binary number');
        Error:=True;
        Break;
      end
      else
        OctPart:=OctPart+StrToInt(LastPart[i])*Power(2, 3-i);
    OctStr:=OctStr+FloatToStr(OctPart);
  end;
  Result:='';
  if Error<>True then
  begin
    for i:=1 to Length(OctStr) do
      Result:=Result+OctStr[Length(OctStr)-i+1];
    while (Result[1]='0') and (Length(Result)>1) do
      Delete(Result, 1, 1);
  end;
end;

Related topics
Convert octal to binary
Convert hexadecimal to binary
Convert binary to hexadecimal
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


Our Partner
DevArchive.com
Recommended
just4fun
Useful Resources
Win32.hlp Online
Unix Manual Pages
MegaDetailed.NET
in3steps.com
Newsletters
Subscribe to our news!    Subscribe to our news!


Greatis Software Greatis | Security | AppDatabase | Utilities | Delphi/CB | Visual Basic | .NET | just4fun

Contacts | Add to Favorites | Recommend to a Friend | Privacy Policy | Copyright © 1998-2008 Greatis Software