Lawrence Cooke
Lawrence Cooke

Reputation: 1597

Encoding numbers with base62 and base36

Currently I have some code that converts numbers into base62 format

This works fine, however when putting the data into the database, its possible to end up with two of the same base62 string (but with different case)

eg. SsUTF1 and Ssutf1

To get around this issue, is base36 a viable alternative to base62? my very limited understanding of this is that base36 wont produce same strings, but on the flip side, I am assuming the character length for bigger numbers can be longer on base 36 than base 62?

if I have strings in the database already that are base62 , is it possible to end up with duplicates after switching to base36? given that the base number the strings will be derived from are never going to be the same.

Upvotes: 0

Views: 933

Answers (1)

Jimbot
Jimbot

Reputation: 716

Given that the base number is different, it base36 representation will always be different. it's also true with base62 if you compare it using case sensitive or binary compare method.

Also base36 representation of the same number could be longer than the base62. Let say we have 10 positions it would mean we could represent :

  • base36 36E10 = 3 656 158 440 062 976 possibilities
  • base62 62E10 = 839 299 365 868 340 224 possibilities

Hope this help.

Upvotes: 1

Related Questions