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') );
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.