1

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?

Robbie Dee
9,8332 gold badges25 silver badges53 bronze badges
asked Mar 23, 2016 at 10:17
0

1 Answer 1

10

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 1111111111111111111111111111111
Ternary 12112122212110202101
Quaternary 1333333333333333
Quinary 13344223434042
Senary 553032005531
Octal 17777777777
Decimal 2147483647
Duodecimal 4BB2308A7
Hexadecimal 7FFFFFFF
Vigesimal 1DB1F927
Base 36 ZIK0ZJ

Base 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.

answered Mar 23, 2016 at 10:40
2
  • Good stuff. BTW, base 36 is commonly called: Hexatrigesimal Commented Mar 23, 2016 at 11:10
  • 1
    base 63 and 85 are also fairly common Commented Mar 23, 2016 at 16:24

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.