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 .travis.yml
Octocat-spinner-32 .yardopts
Octocat-spinner-32 Gemfile
Octocat-spinner-32 MIT-LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 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.