Search code examples
pascallazarus

OctToInt in Pascal


I'm writing assembler for imaginary processor of my design (kinda like DCPU-16) and I want to include all major number bases. I've got hex,bin and dec, but I cannot get oct, because there seem to be no OctToInt function. Any help?


Solution

  • function OctToInt(Value: string): Longint; 
      var
        i, int: Integer;
    begin
      int := 0;
      for i := 1 to Length(Value) do
        int := int * 8 + StrToInt(Copy(Value, i, 1));
    Result := int;
    end;