As you might have guessed, this is for generating short URLs.
What's the best way to compact a 96-bit integer into a URL friendly 开发者_StackOverflowshort string? Is Base64 the best way or are there any alternatives?
I would use base64 for this. It protects you from illegal characters and generates string that 'look' a little like being human-readable.
you could calculate the bit sum
An easy approach is a modified Base 64 encoding. The original Base 64 won't work because it uses the plus (+) and slash (/) character, which have a special meaning in URLs.
But if you replace these characters with a minus (-) and underscore(_) character, you have a nice solution.
If I'm not mistaken, there are 65 or 66 URL-safe characters. So a modified Base 64 comes pretty close to the optimum.
What about converting it to hexadecimal?
精彩评论