Coder Social home page Coder Social logo

rebase-ruby's Introduction

Rebase

Convert integers to a given base and back again. Accepts bases 2—62, or an array of an arbitrary alphabet.

Build Status Code Climate

require 'rebase'

Base62 = Rebase(62)
Base62.encode(10622433094) # => "Base62"
Base62.decode('Base62') # => 10622433094

# Extensions to String and Integer
require 'rebase/ext'

'Base62'.decode_base(62) # => 10622433094
10622433094.encode_base(62) # => "Base62"

Rebase(base[, int])

Base can be an integer between 2 and 62, an array forming a custom alphabet (items are expected to respond to #to_s), or the symbol :hex or :binary for base 16 and base 2 respectively. Passing the optional int is the equivalent of calling Rebase(base).encode(int).

encode(int)

Returns string representation of int in a given base. int must be non negative, otherwise it raises an ArgumentError.

decode(str)

Returns integer representation of str in base 10. str must not be blank or contain invalid characters, otherwise it raises an ArgumentError.

License

The MIT License. Copyright © 2014 Larry Fox

rebase-ruby's People

Contributors

larryfox avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.