Skip to content
This repository

Any formats can mean positional/unary numeral systems :)

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 History.rdoc
Octocat-spinner-32 LICENSE
Octocat-spinner-32 Manifest.txt
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
README.rdoc

integer-base

Description

Your format comes into positional numeral systems.

Feautures

  • 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

Usage

  • 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]         #=> 36
    '10'.to_i Integer::Base::STANDARD_CHARS[:BINARY]    #=> 2
  • 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

Requirements

  • Ruby 1.9.2 or later

    Focusing

    • 1.9.3-p194

    • 1.9.2-p290

Installation

  • gem install integer-base

License

The MIT X11 License

Copyright © 2011 Kenichi Kamiya

See the file LICENSE for further details.

Something went wrong with that request. Please try again.