[][src]Crate bibicode

This crate can be used to convert any integer from one numeral system to another.

Two numeral systems must be defined : one for the input number and one for the output.

Any integer (of any length) can then be converted from one system to the other and vice-versa.

This library uses an extension of shift-adjust algorithm (and reversed shift-adjust) to convert numbers. Binary is used as a pivot radix. This method was described here : Convert binary number to any base.

It was named after french singer (and also mathematician) Boby Lapointe who invented the Bibi-binary system in 1968.

Exemple

   extern crate bibicode;

   let dec = bibicode::NumeralSystem::new("", vec!(vec!("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"))).unwrap();
   let bibi = bibicode::NumeralSystem::new("", vec!(vec!("HO", "HA", "HE", "HI", "BO", "BA", "BE", "BI", "KO", "KA", "KE", "KI", "DO", "DA", "DE", "DI"))).unwrap();
   let coder = bibicode::BibiCoder::new(dec, bibi);
   let test = coder.swap("2000").unwrap();
   assert_eq!(test, "BIDAHO");

   let bibi = bibicode::NumeralSystem::new("", vec!(vec!("H", "B", "K", "D"), vec!("O", "A", "E", "I"))).unwrap();
   let dec = bibicode::NumeralSystem::new("", vec!(vec!("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"))).unwrap();
   let coder = bibicode::BibiCoder::new(dec, bibi);
   let test = coder.swap("2000").unwrap();
   assert_eq!(test, "BIDAHO");

   // with prefixed numeral system
   let dec = bibicode::NumeralSystem::new("", vec!(vec!("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"))).unwrap();
   let hex = bibicode::NumeralSystem::new("0x", vec!(vec!("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"))).unwrap();
   let coder = bibicode::BibiCoder::new(dec, hex);
   let test = coder.swap("2000").unwrap();
   assert_eq!(test, "0x7d0");

   let dec = bibicode::NumeralSystem::new("", vec!(vec!("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"))).unwrap();
   let hex = bibicode::NumeralSystem::new("0x", vec!(vec!("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"))).unwrap();
   let coder = bibicode::BibiCoder::new(hex, dec);
   let test = coder.swap("0x7d0").unwrap();
   assert_eq!(test, "2000");
   // will also work
   let test = coder.swap("7d0").unwrap();
   assert_eq!(test, "2000");

Structs

BibiCoder

Convert any number from one numeral system to the other.

NumeralSystem

Define a numeral system by enumerating all the digits. The first digit is zero. The radix is equal to the number of digits. One digit can have any number of characters but all digits must have the same length.

Enums

BibiError