Standard Base62 Encoding?

I

Intransition

Is there a standard encoding for base62? I've been using 0..9a..zA..Z,
but I think I should switch that to 0..9A..Za..z, so it would sort
properly according to ASCII order. I wasn't able to find anything on a
standard via a Google search. So maybe there just isn't one?

I was kind of surprised to see Ruby uses lower case a..f for
hexadecimal rather than uppercase.

"255.to_s(16) #=> "ff"
 
W

w_a_x_man

Is there a standard encoding for base62? I've been using 0..9a..zA..Z,
but I think I should switch that to 0..9A..Za..z, so it would sort
properly according to ASCII order. I wasn't able to find anything on a
standard via a Google search. So maybe there just isn't one?

I was kind of surprised to see Ruby uses lower case a..f for
hexadecimal rather than uppercase.

  "255.to_s(16)  #=> "ff"

Where is base 62 used?
 
R

Robert Klemme

Is there a standard encoding for base62? I've been using 0..9a..zA..Z,
but I think I should switch that to 0..9A..Za..z, so it would sort
properly according to ASCII order. I wasn't able to find anything on a
standard via a Google search. So maybe there just isn't one?

I was kind of surprised to see Ruby uses lower case a..f for
hexadecimal rather than uppercase.

"255.to_s(16) #=> "ff"

irb(main):003:0> "0x%02X" % 255
=> "0xFF"

I have no idea though, why you want to use Base62 encoding when there is
a standard implementation of Base64 encoding.

irb(main):005:0> require 'base64'
=> true
irb(main):006:0> Base64.encode64 "\000\001"
=> "AAE=\n"

Kind regards

robert
 
S

Steve Klabnik

[Note: parts of this message were removed to make it a legal post.]

Even easier, for base64, no requires needed.

ruby-1.9.2-p0 > ["\000\001"].pack("m")
=> "AAE=\n"
 
I

Intransition

irb(main):003:0> "0x%02X" % 255
=3D> "0xFF"

I have no idea though, why you want to use Base62 encoding when there is
a standard implementation of Base64 encoding.

I'm not using it as such. My question is for my Radix project which
can convert any base to any other. 62 is the max limit for a string
representation of a number. I wanted to keep them limited to Latin
characters.

As for as base-62, from what I understand is used for basically that
same reason. Say you want to "scramble" file names, but need to make
sure they are still valid filenames. Encoding in Base-62 is good for
that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top