Answer the question
In order to leave comments, you need to log in
How to convert BASE62 to BINARY?
Hi all!
In my application, I generate Base62 unique identifiers with a length of 20 characters and store them in MySQL.
Identifier examples:
xQkmfxYVBLicFvaw2ECL
5JhHXRYSSI6lVnOxzgOX
... and so on
Answer the question
In order to leave comments, you need to log in
Don't get a big win. 62 and 256 are 6 and 8 bits respectively, i.e. savings up to 25%.
How to convert, there are several options:
1) convert each character in the string to a binary code of 6 bits, pad the resulting string to a length multiple of 8, convert 8 bits into characters.
2) Make a table of 4 base62 characters, which will uniquely match 3 base256 characters. Complement the string to a length multiple of 4 characters, take 4 characters each and from the table they will correspond to 3 base256 characters
.
The general rule that I came up with for myself at school: if a, b are number systems and ifa^N = b^M , then every N characters in system a is replaced by M characters in system b .
For example:
convert 10101010101010101010101 from binary to 8ary system: [2^3 = 8^1]
(0)10 101 010 101 010 101 010 101 (_2) = 25252525 (_8)
convert 102301023001230 from 4th to 8ary system: [2^3 = 8^2]
102 301 023 001 230 (_4) = 22 61 13 01 54 (_8)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question