Hier noch die 35er Variante mit 0 bis 9 und A bis Z (Buchstabe O weggelassen wegen Ähnlichkeit zu Zahl 0):
Delphi-Quellcode:
function IntPowerInt(ABaseNum, AExponent : Integer) : Integer;
var
MultCount : Integer;
begin
Result := 1;
for MultCount := 1 to AExponent do
Result := Result * ABaseNum;
end;
function AlphaToNum(ATNstr : String ) : LongWord;
const
ValidChars : set of Char = ['0'..'9', 'A'..'N', 'P'..'Z'];
var
ACount : Integer;
function CharNum(CNchr : Char) : Byte;
begin
Case Ord(UpCase(CNchr)) Of
48..57: CharNum := Ord(UpCase(CNchr)) - 48;
65..78: CharNum := Ord(UpCase(CNchr)) - 55;
80..90: CharNum := Ord(UpCase(CNchr)) - 56;
end;
end;
begin
AlphaToNum := 0;
for ACount := 1 to length(ATNstr) do
begin
If not (UpCase(ATNstr[ACount]) in ValidChars) then
begin
result := 0;
Break;
end;
result := result + (CharNum(ATNstr[ACount]) * IntPowerInt(35, length(ATNstr) - ACount));
end;
end;
function NumToAlpha(NTAnum : LongWord ) : String;
var
NumChar : array[0..34] Of Char;
NumCount : Word;
begin
for NumCount := 0 to 9 do NumChar[NumCount] := Chr(48 + NumCount);
for NumCount := 10 to 23 do NumChar[NumCount] := Chr(55 + NumCount);
for NumCount := 24 to 34 do NumChar[NumCount] := Chr(56 + NumCount);
// max 35 hoch (7-1)
result := '';
for NumCount := 7 downto 1 do
If (NTAnum < IntPowerInt(35, NumCount)) then
begin
result := result + NumChar[NTAnum div IntPowerInt(35, NumCount-1)];
NTAnum := NTAnum mod IntPowerInt(35, NumCount-1);
end;
end;
Delphi-Quellcode:
s1 := 'AZGE';
s2 := 'X45B';
s3 := NumToAlpha(AlphaToNum(s1) + AlphaToNum(s2));