I need to compress an id for marketing campaigns. The current campaign id is 32-bit integer but obviously this is too long for a customer to type by hand. I would like to compress this to minimum length while still maintaining two-way compression/decompression and uniqueness of id. What algorithm should I use?
Best two-way compression algorithm for 32-bit numbers
algorithms;compression
A 32-bit id is so little data with so little redundancy to exploit that a true compression algorithm is likely not going to help much. On the other hand, simply using a higher numeric base where you use letters as well as digits to represent the number probably accomplishes exactly what you're after. For example, here's the largest possible 32-bit integer value in different bases:Binary      1111111111111111111111111111111Ternary     12112122212110202101Quaternary  1333333333333333Quinary     13344223434042Senary      553032005531Octal       17777777777Decimal     2147483647Duodecimal  4BB2308A7Hexadecimal 7FFFFFFFVigesimal   1DB1F927Base 36     ZIK0ZJBase 36 is a logical stopping point because the letters A-Z and the digits 0-9 give you exactly 36 symbols, so going to even higher bases would require introducing something less obvious and possibly difficult to type.A six-digit number should be short enough for anyone to easily type by hand. I'll assume you can work out the trivial algorithm to convert a number from one base to another on your own.