|
Convert octal to decimal
Use function OctToDec to convert number in octal format to decimat format. It is not very difficult, because 217 in octal is 2*8*8+1*8+7 in decimal format.
function OctToDec(OctStr: string): string;
var
DecNum: Real;
i: Integer;
Error: Boolean;
begin
DecNum:=0;
Error:=False;
for i:=Length(OctStr) downto 1 do
begin
if not (OctStr[i] in ['0','1','2','3','4','5','6','7']) then
begin
Error:=True;
ShowMessage('This is not octal number');
Break;
end;
DecNum:=DecNum+StrToInt(OctStr[i])*Power(8, Length(OctStr)-i);
end;
if not Error then
Result:=FloatToStr(DecNum)
else Result:='';
end;
- Related topics
-
Convert binary to octal
Convert octal to binary
Convert hexadecimal to binary
Convert binary to hexadecimal
Convert decimals to binary
Convert decimals to hexadecimals
Convert hexadecimals to decimals
Convert binary to decimals
- For more
-
Delphi Help
- Download source
|