number systems/de
Zurück zur Seite Code Beispiele.\
Diese Seite beeinhaltet die Umrechnung von Zahlensystemen.
Die beiden Funktionen rechnen Ganzzahlen zwischen dem Dezimalsystem und einem beliebigen Zahlensystem nach dem Hornerschema um.\
uses
...;
...
implementation
..
const
conCharDigits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
...
function funXInDec(conZahl: string; bytQuellsystem: byte): int64;
// Die Funktion rechnet jeden Zahlsystem in das Dezimalsystem um
// Parameter:
// Zahl, Zahlensystem
// Aufruf der Funktion: funXToDec('10100111', 2);
var
intFor: integer;
bytWert: byte;
begin
Result := 0;
for intFor := 1 to Length(conZahl) do
begin
bytWert := Pos(conZahl[intFor], conCharDigits) - 1;
if (bytWert >= bytQuellsystem) then
begin
// Das Unterprogramm wird im Fehlerfall beendet
Result := 0;
Exit;
end;
Result := Result * bytQuellsystem + bytWert;
end;
end;
function funDecToX(i64Quelle: int64; bytZielsystem: byte): string;
// Die Funktion rechnet das Dezimalsystem in jedes beliebige Zahlensystem um
// Parameter:
// Zahl, Zahlensystem
// Aufruf der Funktion: funDecToX(ZwischenSystem, 16);
begin
Result := '';
repeat
Result := conCharDigits[(i64Quelle mod bytZielsystem) + 1] + Result;
i64Quelle := i64Quelle div bytZielsystem;
until (i64Quelle = 0);
end;
...From the Free Pascal wiki, page "number systems/de", as it stood on 2020-02-21 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
