irb irb main 001 require base_converter true irb main 002 binconv Base

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$ irb
irb(main):001:0> require 'base_converter'
=> true
irb(main):002:0> binconv = BaseConverter.new("01")
=> #<BaseConverter:0xb7c987d8 @digits="01", @decimal_digits="0123456789">
irb(main):003:0> binconv.from_decimal(10)
=> "1010"
irb(main):004:0> binconv.from_decimal(10123)
=> "10011110001011"
irb(main):005:0> binconv.to_decimal(10011110001011)
=> "10123"
irb(main):006:0> hexconv = BaseConverter.new("0123456789ABCDEF")
=> #<BaseConverter:0xb7c4f5d8 @digits="0123456789ABCDEF", @decimal_digits="0123456789">
irb(main):007:0> hexconv.from_decimal(255)
=> "FF"
irb(main):008:0> hexconv.from_decimal(256)
=> "100"
irb(main):009:0> hexconv.from_decimal(255)
=> "FF"
irb(main):010:0> base62 = BaseConverter.new "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"
=> #<BaseConverter:0xb7c62ca0 @digits="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz", @decimal_digits="0123456789">
irb(main):014:0> base62.from_decimal(987654321)
=> "BEqGAZ"
irb(main):015:0> base62.from_decimal(987654321123123123)
=> "BKx2yLRjbzR"
irb(main):016:0> base62.to_decimal "BKx2yLRjbzR"
=> "987654321123123123"