Giter Club home page Giter Club logo

base_convert's Introduction

Base Convert [2..64]

Build Status GitHub license GitHub stars awesomeness

PHP's built in base_convert function supports bases ranging from 2 to 36. This library expands that range to 2 to 64.

Usage

Convert a number 100 from decimal to hexadecimal (from base 10 to base 16):

echo math\base_convert(100, 10, 16); 
// echoes '64'

...and back:

echo math\base_convert(64, 16, 10); 
// echoes '100'

Custom alphabets

Instead of integer bases, you can pass in the alphabet string to use for conversion (since integer bases are converted to alphabet strings anyways, i.e. hexadecimal alphabet is simply "0123456789abcdef").

Here we convert from base 10 to alphabet 'customizable'

echo math\base_convert(1234567890, 10, 'customizable');
// echoes 'slmmmmcui'

Here we convert from alphabet 'customizable' to alphabet 'isogram'

echo math\base_convert('slmmmmcui', 'customizable', 'isogram');
// echoes 'rorsirrioig'

And from alphabet 'isogram' back to base 10

echo math\base_convert('rorsirrioig', 'isogram', 10);
// echoes '1234567890'

So both slmmmmcui and rorsirrioig, but also 1234567890 describe the same value, but in different alphabets.

NOTE: All alphabets must be isograms An isogram (also known as a "nonpattern word") is a logological term for a word or phrase without a repeating letter. Conveniently, the word isogram is an isogram as well.

License

MIT

base_convert's People

Contributors

artbit avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

base_convert's Issues

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.