in reply to Shorter ID Codes

First of all, you are talking about converting (I assume) a decimal number, which has 10 values per character, to a combination of digits and uppcase letters, which has 36 values per digit. So the best compression ratio you can expect is log_10(36) or about 1.56. The compression ratio of 2 you give as an example isn't possible unless the ID structure has some sparsity that you can exploit.

So the procedure is to convert base 10 number to base 36, and then assign number and letters. Let's take 0-9 to be just 0-9 and 10-35 to be A-Z. Then the encoding step would be

use Math::BaseCalc; $calc36 = new Math::BaseCalc(digits=>[0..9,'A'..'Z']; $calc10 = new Math::BaseCalc(digits=>[0..9]); $in_base_36 = $calc36->to_base($calc10->from_base('4345317546') ); $in_base_10 = $calc10->to_base( $calc36->from_base('DA5BG') );

-Mark

Replies are listed 'Best First'.
Re^2: Shorter ID Codes
by diotalevi (Canon) on Oct 28, 2004 at 18:17 UTC
    The sparcity could come from asserting that no id numbers lower than 4345317546 will be produced anymore so you can substract that base number and end up with really short things like '1' -> 'ZZZ....'.