base-converter

Crates.iobase-converter
lib.rsbase-converter
version2.0.0
sourcesrc
created_at2022-11-05 15:24:27.610409
updated_at2023-12-11 03:34:15.296915
descriptionConvert a number in any base to any other base
homepage
repositoryhttps://github.com/ctison/base-converter
max_upload_size
id705860
size22,807
Charles Tison (ctison)

documentation

README

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
Commit count: 126

cargo fmt