I am writing a program that converts an Octal number to Decimal and Hexadecimal. I wrote a function called OctToInt
.
function OctToInt(Value: string): Longint;
var
i: Integer;
int: Integer;
begin
int := 0;
for i := 0 to Length(Value) do
begin
int := int * 8 + StrToInt(Copy(Value, i, 1));
end;
Result := int;
end;
I call this function in this way:
var oct:integer;
begin
oct:=OctToInt(Edit13.Text);
Edit15.Text:=IntToStr(oct);
end;
When I type 34
(Octal) the decimal number should be 28 but the program gives me 220. Do you know why?
Also, do you have any idea about a converter OctToHex?