Skip to content

Instantly share code, notes, and snippets.

@rummelonp
Last active December 12, 2015 02:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rummelonp/4698505 to your computer and use it in GitHub Desktop.
Save rummelonp/4698505 to your computer and use it in GitHub Desktop.
64進数的な
# -*- coding: utf-8 -*-
class Integer
S64_MAP = ('0'..'9').to_a +
('a'..'z').to_a +
('A'..'Z').to_a +
['_']
def to_s64
s, i, base, negative = '', self, S64_MAP.size, false
return '0' if i == 0
if i < 0
i = -i
negative = true
end
while i > 0
s << S64_MAP[i % base]
i /= base
end
s << '-' if negative
s.reverse
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment