The characters and order required for the 62 hexadecimal notation: 0... 9 a. z A. Z; only the 62 hexadecimal notation string and positive integer are exchanged.
Unit H62; interfaceuses sysutils; function inttoh62 (N: uint64): string; // convert the integer to the 62-digit string function h62toint (S: string): uint64; // convert the 62-digit string to the integer implementationfunction _ C2B (C: Char): byte; inline; begin result: = 0; If charinset (C, ['0 '.. '9']) Then exit (byte (c)-48); // 0 .. 9 If charinset (C, ['A '.. 'Z']) Then exit (byte (c)-97 + 10); // .. Z if charinset (C, ['A '.. 'Z']) Then exit (byte (c)-65 + 36); // .. zend; function _ B2C (B: byte): Char; inline; begin result: = #0; if B = 10) and (B = 36) and (B 0) then result: = _ C2B (c) * _ Power (62, n); end; function inttoh62 (N: uint64): string; var C: Char; begin result: = ''; repeat C: = _ B2C (N mod 62); Result: = C + result; N: = N Div 62; until (n = 0); end; function h62toint (S: string): uint64; var C: Char; L, N, I: Cardinal; begin result: = 0; L: = length (s ); if l> 11 then raise exception. create ('err: h62toint'); // no more than 11 bits for I: = L downto 1 do begin C: = s [I]; N: = l-I; result: = Result + _ C2v (C, N); end.
// Test: Uses H62; Procedure tform1.formcreate (Sender: tobject); var N: Cardinal; I: uint64; STR: string; begin STR: = inttoh62 (maxint ); // 2lkcb1 N: = h62toint (STR); // 2147483647 I: = 9999999999999999999; // 19-bit STR: = inttoh62 (I); // bui6zolztrh STR: = 'zzzzzzzzz'; // maximum I: = h62toint (STR); // 15143072536417990655; smaller than the maximum value (18446744073709551615) of uint64, and larger than the maximum value (9223372036854775807) of int64. end;