Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there multiple Base62 Encoding Algorithm?

I was watching a tutorial regarding system design for tiny url, and reading up on base62 encoding to avoid collision. They say to use a counter, and encode it with base62. Now this makes sense but looking at some online base62encoder, if the tiny url limit character say only 7 characters, if some of the encoder generate more than 7 characters. Are there multiple type of base62 encoding? e.g this two websites, gives 2 different result for same input of 1000000 enter image description here

enter image description here

like image 551
Harts Avatar asked Sep 14 '25 08:09

Harts


1 Answers

Base62 and Base64 encodings are used to represent binary data as text.

I am not sure what practical use base62 has. base64, on another hand, can represent 6 bits as one character, Your sample value 1,000,000 (hex 0xF4240) uses 20 bits, so it fits into 4 base64 characters.

Your first example uses a plain text 1000000, which is 7 characters, 8-bit each. Or total of 56 characters, that would require 10 base64 characters.

You will get similar numbers for base62, but the encoding must be non-trivial, as you can't simply chop your data into 6-bits pieces.

Wiki link above mentions multiple variants, so you do have to agree between encoder and decoder - which one to use. But this is NOT the issue you saw in your two examples.

like image 85
Vlad Feinstein Avatar answered Sep 17 '25 20:09

Vlad Feinstein