Autor Beitrag
R4id
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 28

Win XP Home, Win XP Prof.
D7 Prof., D2006 Arch., BCB2006 Arch.
BeitragVerfasst: Mo 29.06.09 19:33 
Hallo alle zusammen :wave:

Ich habe mir hier mal 2 Konverter Funktionen gebastelt weil ich sie nirgentwo gefunden habe, sie wandeln Integer in Oktalzahlen um, nun hab ich mich gefragt ob das nicht vllt. ein stück einfacher gehen würde :gruebel:

Hier mal die Funktionen:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
function IntToOkt(const Value: Int64): Int64;
type
  TDivideRest = array [0..1of Integer;

  { Dividiert eine Zahl und gibt ein Ergebnis mit Rest zurück }
  function DivideRest(const Dividend, Divisor: Integer): TDivideRest;
  begin
    Result[0] := 0;
    Result[1] := 0;

    if (Dividend div Divisor) = (Dividend / Divisor) then
      Result[0] := Dividend div Divisor
    else begin
      Result[0] := Dividend div Divisor;
      Result[1] := Dividend - (Result[0] * Divisor);
    end;
  end;

var
  Divide: array of TDivideRest;
  S: string;
begin
  Result := 0;
  SetLength(Divide, 1);
  Divide[High(Divide)] := DivideRest(Value, 8);
  S := IntToStr(Divide[High(Divide)][1]);

  while (0 <> Divide[High(Divide)][0]) do
  begin
    SetLength(Divide, Length(Divide) + 1);
    Divide[High(Divide)] := DivideRest(Divide[High(Divide) - 1][0], 8);
    S := IntToStr(Divide[High(Divide)][1]) + S;
  end;

  Result := StrToInt(S);
end;

function OktToInt(const Value: Int64): Int64;

  function Power(const Base, Exponent: Integer): Integer;
  var
    I: Integer;
  begin
    Result := Base;

    case Exponent of
      0: Result := 1;
      1: Result := Base;
      else
        for I := 1 to Exponent - 1 do
          Result := Base * Result;
    end;
  end;

var
  I: Integer;
  S, W: string;
begin
  S := IntToStr(Value);

  for I := 1 to Length(S) do
    W := IntToStr(StrToIntDef(W, 0) + StrToInt(S[I]) * Power(8, Length(S) - I));

   Result := StrToInt(W);
end;


Gruß, R4id
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19341
Erhaltene Danke: 1752

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 29.06.09 19:44 
In der Library findest du u.a. diese Umwandlungsroutine, die von verschiedenen Basen in andere umwandelt.
www.delphi-library.d...ewtopic.php?p=245270