项目作者: kachick

项目描述 :
Any formats can mean positional/unary numeral systems :)
高级语言: Ruby
项目地址: git://github.com/kachick/integer-base.git
创建时间: 2012-01-15T08:47:40Z
项目社区:https://github.com/kachick/integer-base

开源协议:MIT License

下载


integer-base

  • This repository is archived
  • No longer maintained
  • All versions have been removed from https://rubygems.org to free up valuable namespace for other developers.

Build Status

Description

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

Features

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

Usage

Introduction

  1. require 'integer/base'
  2. Integer::Base.parse '10', %w[0 1 2 3 4 5 6 7 8 9] #=> 10
  3. # Extend core methods with refinement
  4. using Integer::Base
  5. '10'.to_i %w[0 1] #=> 2
  6. 10.to_s %w[0 1] #=> "2"

Upper 36 base number

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

Actual usecase, special mapping as Crockford’s base32

  1. 1998335352370349147064579878655797352.to_s('0123456789ABCDEFGHJKMNPQRSTVWXYZ'.chars)
  2. # => "1g3erma7w2dm6934zqz3qda38"

Let’s begin, your strange base number.

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

License

The MIT X11 License
Copyright (c) 2011 Kenichi Kamiya