#base #conversion #convert

bin+lib base-converter

Convert a number in any base to any other base

9 releases (1 stable)

2.0.0 Dec 11, 2023
2.0.0-beta.6 Dec 10, 2023
2.0.0-beta.3 Nov 9, 2022
2.0.0-alpha.3 Nov 5, 2022
0.0.0 Nov 8, 2022

#270 in WebAssembly

Download history 45/week @ 2024-07-20 4/week @ 2024-07-27 47/week @ 2024-08-03 117/week @ 2024-08-10 61/week @ 2024-08-17 32/week @ 2024-08-24 96/week @ 2024-08-31 51/week @ 2024-09-07 31/week @ 2024-09-14 47/week @ 2024-09-21 34/week @ 2024-09-28 68/week @ 2024-10-05 54/week @ 2024-10-12 38/week @ 2024-10-19 21/week @ 2024-10-26 45/week @ 2024-11-02

160 downloads per month

MIT license

12KB
190 lines

Base converter

Convert a number from any base to any other base from your terminal!

Install

Pre-built binaries are available in Releases.

NPM package (wasm) available at https://www.npmjs.com/package/@ctison/base-converter.

Rust doc available at https://docs.rs/base-converter/latest/base_converter/.

CLI Usage

$ base-converter <NUMBER> <FROM_BASE> <TO_BASE>
# Convert 51966 from base 10 to base 16
$ base-converter 51966 0123456789 0123456789ABCDEF
CAFE
# Convert 42 from base 10 to base 2
$ base-converter 42 0123456789 🦀🚀
🚀🦀🚀🦀🚀🦀

NPM usage

$ npm add @ctison/base-converter
/**
 * Checks if a base is valid by throwing an error if not.
 * @param {string} base
 */
export function checkBase(base: string): void
/**
 * Convert a number from any base to an decimal number.
 * @param {string} nbr
 * @param {string} fromBase
 * @returns {number}
 */
export function baseToDecimal(nbr: string, fromBase: string): number
/**
 * Convert an decimal number to any base.
 * @param {number} nbr
 * @param {string} toBase
 * @returns {string}
 */
export function decimal_to_base(nbr: number, toBase: string): string
/**
 * Convert a number from any base to any base.
 * @param {string} nbr
 * @param {string} fromBase
 * @param {string} toBase
 * @returns {string}
 */
export function baseToBase(
  nbr: string,
  fromBase: string,
  toBase: string
): string

Dependencies

~0.4–1.1MB
~24K SLoC