Radix
DESCRIPTION
Radix provides the means of converting to and from any base.
In addition, representational notations need not be in ASCII order –any user-defined notation can be used up to base 62.
FEATURES/ISSUES
-
Convert to and from any base.
-
User-definable character set upto base 62.
-
Defaults to standard base 62.
-
Can be used to encode strings.
RELEASE NOTES
Please see HISTORY file.
SYNOPSIS
Base conversions with ASCII ordered notations are easy in Ruby.
255.to_s(16) #=> "FF"
"FF".to_i(16) #=> 255
But Ruby reaches it’s limit at base 36.
255.to_s(37) #=> Error
Radix provides the means of converting to and from any base. For example, a number in base 256, represented by the array [100, 10] (ie. 100 * 256 + 10 * 1), can be converted to base 10 as follows:
Radix.convert_base([100, 10], 256, 10)
#=> [2,5,6,1,0]
And it can handle any string notation up to base 62.
Radix.convert("10", 62, 10) #=> "62"
The string notation need not be in ASCII order –odd notations can be used.
b10 = Radix.new([:Q, :W, :E, :R, :T, :Y, :U, :I, :O, :U])
b10.convert("FF", 16) #=> "EYY"
HOW TO INSTALL
To install with RubyGems simply open a console and type:
gem install radix
Site installation requires Setup.rb (gem install setup), then download the tarball package and type:
tar -xvzf radix-1.0.0.tgz
cd radix-1.0.0
sudo setup.rb all
Windows users use ‘ruby setup.rb all’.
LINCENSE/COPYRIGHT
Copyright © 2009 Thomas Sawyer
This program is ditributed unser the terms of the LGPLv3 license.
See LICENSE file for details.