Crate number_based

source ·
Expand description

Overview

Converting a uBase/iBase instance

// converting down

// create uBase instance
let mut number = uBase::from_string(7863, "NUMBERBASED");

// convert number to base 10
number.convert(10);

assert_eq!(number.display(), String::from("20781774882369576414324066149192513674771"));
// Do aslso note that number.conver(10).display() is equivalent to number.as_decimal() with the
// important distinction that as_decimal() returns a u128 and not a string





// converting up

// create uBase instance
let mut other_number = uBase::from_string(10, "120387517860123746975");

// convert number to base 10000
other_number.convert(10000);

assert_eq!(other_number.display(), String::from("1ࡒᶹ⇵ঢᮛ"));

Performing operations with uBase/iBase instances

// create the iBase instances
let number1 = iBase::from_string(30000, "-ð䧈炙㞈榻");
assert_eq!(number1.as_decimal(), -120387517860123746975);

let number2 = iBase::from_string(30000, "20");
assert_eq!(number2.as_decimal(), 60000);

// divide the numbers
let quotient = number1 / number2;
// other operations such as addition, subtraction, and multiplication are also available with
// the operators "+", "-", and "*" respectively

assert_eq!(quotient.display(), String::from("-¦┒㡺嚊"));
assert_eq!(quotient.as_decimal(), -120387517860123746975 / 60000);

Traits

Type Definitions