Last active
December 12, 2015 02:28
-
-
Save rummelonp/4698505 to your computer and use it in GitHub Desktop.
64進数的な
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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