#numeric #base #conversion #decimal

base_custom

Use any characters as your own numeric base and convert to and from decimal

15 releases

0.2.0 Dec 7, 2018
0.1.13 Dec 9, 2017
0.1.12 Oct 29, 2017
0.1.10 Sep 22, 2017
0.1.6 Jun 24, 2017

#168 in Data structures

Download history 1/week @ 2019-07-24 1/week @ 2019-07-31 21/week @ 2019-08-07 3/week @ 2019-08-14 33/week @ 2019-08-21 53/week @ 2019-08-28 26/week @ 2019-09-04 34/week @ 2019-09-11 181/week @ 2019-09-18 34/week @ 2019-09-25 19/week @ 2019-10-02 4/week @ 2019-10-09 65/week @ 2019-10-16 25/week @ 2019-10-23 35/week @ 2019-10-30

94 downloads per month
Used in 2 crates (1 directly)

MIT/Apache

19KB
263 lines

base_custom

Build Status crates.io version License

Use any characters as your own numeric base and convert to and from decimal. This can be taken advantage of in various ways:

  • Mathematics: number conversion
  • Brute force sequencing
  • Rolling ciphers
  • Moderate information concealment
  • Other potential uses such as deriving music or art from numbers

There is also a Ruby and Crystal implementation of this which this was based off of.

Installation

Add the following to your Cargo.toml file

[dependencies]
base_custom = "^0.2"

To include it for usage add

extern crate base_custom;
use base_custom::BaseCustom;

to your file.

Usage

// Binary with no delimiter
let base2 = BaseCustom::<char>::new("01".chars().collect());
assert_eq!(base2.decimal("00001"), 1_u64);
assert_eq!(base2.decimal("100110101"), 309_u64);
assert_eq!(base2.gen(340), "101010100");
assert_eq!(base2.gen(0xF45), "111101000101");
assert_eq!(base2.gen(0b111), "111");

// Trinary with no delimiter
let base3 = BaseCustom::<char>::new("ABC".chars().collect());
assert_eq!(base3.decimal("ABC"), 5);
assert_eq!(base3.gen(123), "BBBCA");

// Custom base like Musical Chords and a space delimiter
let base_music = BaseCustom::<String>::new("A A# B C C# D D# E F F# G G#", Some(' '));
assert_eq!(base_music.decimal("F F# B D# D A# D# F# "), 314159265);
assert_eq!(base_music.gen(314159265), "F F# B D# D A# D# F# ");

When using BaseCustom::<String>::new the second parameter must be of Option<char> to choose your optional delimiter.

Benchmarks

Benchmarks are provided for the various usages and implementations. BaseCustom<char> is by far the most efficient implementation.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps