All Projects → thunderer → Numbase

thunderer / Numbase

Licence: MIT license
Arbitrary number base converter.

Programming Languages

PHP
23972 projects - #3 most used programming language
Dockerfile
14818 projects
Makefile
30231 projects

Projects that are alternatives of or similar to Numbase

cpc
Text calculator with support for units and conversion
Stars: ✭ 89 (+304.55%)
Mutual labels:  converter, math
py-persian-tools
An anthology of a variety of tools for the Persian language in Python
Stars: ✭ 106 (+381.82%)
Mutual labels:  digits, number
SurrealNumbers.jl
Implementation of Conway's Surreal Numbers
Stars: ✭ 30 (+36.36%)
Mutual labels:  math, number
NumPad
Number Pad (inspired by Square)
Stars: ✭ 81 (+268.18%)
Mutual labels:  digits, number
Tau.jl
A Julia module providing the definition of the circle constant Tau (2π)
Stars: ✭ 33 (+50%)
Mutual labels:  math, number
persian
Some utilities for Persian language in Go (Golang)
Stars: ✭ 65 (+195.45%)
Mutual labels:  digits, number
BUPT-ICS-Courseware
北京邮电大学 数学系 信息与计算科学专业 课件
Stars: ✭ 76 (+245.45%)
Mutual labels:  math
nodejs-eol-converter-cli
Newline (EOL) coverter CLI for NodeJs. CRLF -> LF or backwards conversion.
Stars: ✭ 33 (+50%)
Mutual labels:  converter
rclc
Mathematical expression calculator with big integers, floats, common fractions, and complex numbers support
Stars: ✭ 24 (+9.09%)
Mutual labels:  math
xml-avro
Convert XSD -> AVSC and XML -> AVRO
Stars: ✭ 32 (+45.45%)
Mutual labels:  converter
webp-wasm
Webp image convertor (webassembly, works offline in browser)
Stars: ✭ 18 (-18.18%)
Mutual labels:  converter
dinputto8
A dll module that is designed to improve compatibility in games using DirectInput 1-7 (dinput.dll) by converting all API calls to their equivalent DirectInput 8 (dinput8.dll) ones. This allows older games to be able to use newer tools and wrappers written for DirectInput 8.
Stars: ✭ 42 (+90.91%)
Mutual labels:  converter
crimson
Bioinformatics tool outputs converter to JSON or YAML
Stars: ✭ 30 (+36.36%)
Mutual labels:  converter
elixir-ms
an elixir microservice base/skeleton 💀
Stars: ✭ 39 (+77.27%)
Mutual labels:  base
css-to-typestyle
Convert raw CSS to TypeStyle
Stars: ✭ 12 (-45.45%)
Mutual labels:  converter
Wallpaper-Engine-Pkg-to-Zip
Simple program to convert the wallpaper engine pkg files to zip and back!
Stars: ✭ 57 (+159.09%)
Mutual labels:  converter
loda
LODA is an assembly language, a computational model and a tool for mining integer sequence programs.
Stars: ✭ 20 (-9.09%)
Mutual labels:  math
it-tools
Aggregated set of useful tools that every developer may need once in a while.
Stars: ✭ 222 (+909.09%)
Mutual labels:  converter
GenericAdapter
⛳️ Easy to use android databinding ready recyclerview adapter
Stars: ✭ 26 (+18.18%)
Mutual labels:  base
gradle2kts
Gradle Groovy to Gradle Kotlin conversion tool - discontinued spike
Stars: ✭ 34 (+54.55%)
Mutual labels:  converter

Numbase

Build License Version Psalm

Easily convert numbers between arbitrary bases and symbol sets.

Installation

This library is available on Packagist as thunderer/numbase. It requires PHP >=7.4 and GMP extension for handling large numbers. For older PHP versions please use ^0.1 constraint which works with 5.3 and above.

Usage

The Simplest Way™

use Thunder\Numbase\Numbase;

$numbase = Numbase::createDefault();

// decimal 15 to hexadecimal number
assert('F' === $numbase->convert(15, 10, 16));
// 64000 decimal to base 32000
assert('20' === $numbase->convert(64000, 10, 32000));

Regular usage (see Internals section for more options):

use Thunder\Numbase\Numbase;

$base62 = new Base62Symbols();
$numbase = new Numbase(new GmpConverter($base62), new StrictFormatter($base62));

// decimal 15 to hexadecimal number
assert('F' === $numbase->convert(15, 10, 16));

Showcase

Convert number to and from a different set of symbols:

$base10 = new Base10Symbols();
$upper = new StringSymbols('!@#$%^&*()');

$numbase = new Numbase(new GmpDigits($base10), new StrictFormatter($upper));

assert('#!' === $numbase->convert('20', 10, 10));
assert('-$!' === $numbase->convert('-30', 10, 10));

$numbase = new Numbase(new GmpDigits($upper), new StrictFormatter($base10));

assert('20' === $numbase->convert('#!', 10, 10));
assert('-30' === $numbase->convert('-$!', 10, 10));

Get array of digit values (for bases too large for any symbol set):

$numbase = new Numbase(new GmpDigits(new Base62Symbols()), new ArrayFormatter());

// convert 10^12 to base 99:
assert(array('10', '61', '53', '3', '51', '60', '10') 
    === $numbase->convert('10000000000000', 10, 99));

Internals

Numbase is built upon several concepts:

  • converters that convert numbers to array of numbers of digits,
  • formatters that take those arrays and return final numbers,
  • symbols used in converters to check symbols values and to get digits symbols in formatters.

There are several implementations of each concept bundled with this library, for example:

  • converters:
    • GmpConverter: can convert any integer between any base greater than 2, uses gmp_*() functions,
    • GmpStrvalConverter: uses gmp_strval() to convert between bases 2 and 62,
    • BaseConvertConverter: uses base_convert() to convert between bases 2 and 32,
  • formatters:
    • ArrayFormatter: returns raw array of digits numbers,
    • StrictFormatter: returns number as string, throws exception when digit is not found in symbols set,
    • FallbackFormatter: returns number as string, but returns string with digit values separated by configured separator when any digit is not found in symbols set,
  • symbols:
    • ArraySymbols: takes associative array(value => symbol),
    • Base62Symbols: contains alphanumeric set of symbols 0-9A-Za-z up to base 62,
    • StringSymbols: takes string and splits it assigning consecutive values to each character.

The named constructor Numbase::createDefault() uses GmpConverter, StrictFormatter and Base62Symbols as defaults.

License

See LICENSE file in the main directory of this library.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].