Your format comes into positional numeral systems.
-
You can build upper 36 basenumbers so easily
-
And get own formats so easily too :)
e.g.
-
0 1 -> 0 a
-
0 1 2 3 4 5 6 7 8 9 -> a b c d e f g h i j
-
-
Setup
require 'integer/base'
-
Basic
Integer::Base.parse '10', %w[0 1] #=> 2
-
Extend Ruby’s Interface
require 'integer/base/ext'
-
to_i
'a'.to_i ['0', *'A'..'I'] #=> 1 'a0'.to_i ['0', *'A'..'I'] #=> 10 'aib'.to_i ['0', *'A'..'I'] #=> 192
-
to_s
192.to_s ['0', *'A'..'I'] #=> 'aib'
-
Already defined useful chars
'10'.to_i Integer::Base::STANDARD_CHARS[36].last #=> :Z '10'.to_i Integer::Base::STANDARD_CHARS[:BINARY].last #=> :"1"
-
Get own formats
'a'.to_i %w[0 a] #=> 1 'a0'.to_i %w[0 a] #=> 2
-
Upper 36 basenumbers
'1!'.to_i([*Integer::Base::STANDARD_CHARS[36], '!']) #=> 73
-
Ruby 1.9.2 or later
Focusing
-
1.9.3-p194
-
1.9.2-p290
-
-
gem install integer-base
The MIT X11 License
Copyright © 2011 Kenichi Kamiya
See the file LICENSE for further details.