Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Any formats can mean positional/unary numeral systems :)

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib/integer
test
.gitignore
.ruby-version
.travis.yml
.yardopts
Gemfile
MIT-LICENSE
README.md
Rakefile
integer-base.gemspec

README.md

integer-base

Build Status Gem Version

Description

Any formats can mean positional/unary numeral systems :)
So base number conversion under your choise.

Features

  • You can easily build base numbers.
  • An example, upper the "36".

Usage

Introduction

require 'integer/base'

Integer::Base.parse '10', %w[0 1 2 3 4 5 6 7 8 9]   #=> 10
Integer::Base.parse '10', %w[0 1]                   #=> 2
Integer::Base.string_for 10, %w[0 1]                #=> '2'


require 'integer/base/core_ext'

'10'.to_i %w[0 1]                                   #=> 2
10.to_s   %w[0 1]                                   #=> "2"

Upper 36 base number

'10'.to_i 36                                        #=> 36
'10'.to_i [*'0'..'9', *'A'..'Z']                    #=> 36
'10'.to_i 37                                        #=> ArgumentError
'10'.to_i [*'0'..'9', *'A'..'Z', '?']               #=> 37
'1?'.to_i [*'0'..'9', *'A'..'Z', '?']               #=> 73 (37 * 1 + 36 * 1)

Let's begin, your strange base number.

':)'.to_i %w[) :]                                   #=> 2

Requirements

Install

$ gem install integer-base

Link

License

The MIT X11 License
Copyright (c) 2011 Kenichi Kamiya
See MIT-LICENSE for further details.

Something went wrong with that request. Please try again.