Hallo alle zusammen
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
Hier mal die Funktionen:
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..1] of Integer;
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