#decimal #base #numeric

based

Custom numeral systems

5 releases (1 stable)

1.0.0 May 30, 2020
0.2.1 Mar 31, 2020
0.1.2 Mar 29, 2020

#1183 in Encoding

MIT/Apache

10KB
212 lines

Documentation Crate

based

based provides support for custom numerical bases. based does not support multi-character digits.

Example

use based::{Base, NumeralSystem};

let base16: Base = "0123456789abcdef".parse().unwrap();
let val: usize = base16.decode("10").unwrap();
assert_eq!(val, 16);
assert_eq!(base16.encode(16 as usize).unwrap(), "10")

lib.rs:

based

based provides support for custom single-character digits.

based does not support multi-character digits.

Examples

use based::{Base, NumeralSystem};

let base16: Base = "0123456789abcdef".parse().unwrap();
let val: usize = base16.decode("10").unwrap();
assert_eq!(val, 16);
assert_eq!(base16.encode(16 as usize).unwrap(), "10")

No runtime deps