Expand description

The BaseFmtWrapper struct and ToStringBase trait, used for converting numbers to strings.

Display::fmt for BaseFmtWrapper

use malachite_base::num::conversion::string::to_string::BaseFmtWrapper;

let x = BaseFmtWrapper::new(1000000000u32, 36);
assert_eq!(format!("{}", x), "gjdgxs");
assert_eq!(format!("{:#}", x), "GJDGXS");
assert_eq!(format!("{:010}", x), "0000gjdgxs");
assert_eq!(format!("{:#010}", x), "0000GJDGXS");

let x = BaseFmtWrapper::new(-1000000000i32, 36);
assert_eq!(format!("{}", x), "-gjdgxs");
assert_eq!(format!("{:#}", x), "-GJDGXS");
assert_eq!(format!("{:010}", x), "-000gjdgxs");
assert_eq!(format!("{:#010}", x), "-000GJDGXS");

Debug::fmt for BaseFmtWrapper

use malachite_base::num::conversion::string::to_string::BaseFmtWrapper;

let x = BaseFmtWrapper::new(1000000000u32, 36);
assert_eq!(format!("{:?}", x), "gjdgxs");
assert_eq!(format!("{:#?}", x), "GJDGXS");
assert_eq!(format!("{:010?}", x), "0000gjdgxs");
assert_eq!(format!("{:#010?}", x), "0000GJDGXS");

let x = BaseFmtWrapper::new(-1000000000i32, 36);
assert_eq!(format!("{:?}", x), "-gjdgxs");
assert_eq!(format!("{:#?}", x), "-GJDGXS");
assert_eq!(format!("{:010?}", x), "-000gjdgxs");
assert_eq!(format!("{:#010?}", x), "-000GJDGXS");

to_string_base

use malachite_base::num::conversion::traits::ToStringBase;

assert_eq!(1000u16.to_string_base(2), "1111101000");
assert_eq!(1000u16.to_string_base(10), "1000");
assert_eq!(1000u16.to_string_base(36), "rs");

assert_eq!(1000i16.to_string_base(2), "1111101000");
assert_eq!(1000i16.to_string_base(10), "1000");
assert_eq!(1000i16.to_string_base(36), "rs");

assert_eq!((-1000i16).to_string_base(2), "-1111101000");
assert_eq!((-1000i16).to_string_base(10), "-1000");
assert_eq!((-1000i16).to_string_base(36), "-rs");

to_string_base_upper

use malachite_base::num::conversion::traits::ToStringBase;

assert_eq!(1000u16.to_string_base_upper(2), "1111101000");
assert_eq!(1000u16.to_string_base_upper(10), "1000");
assert_eq!(1000u16.to_string_base_upper(36), "RS");

assert_eq!(1000i16.to_string_base_upper(2), "1111101000");
assert_eq!(1000i16.to_string_base_upper(10), "1000");
assert_eq!(1000i16.to_string_base_upper(36), "RS");

assert_eq!((-1000i16).to_string_base_upper(2), "-1111101000");
assert_eq!((-1000i16).to_string_base_upper(10), "-1000");
assert_eq!((-1000i16).to_string_base_upper(36), "-RS");

Structs

A struct that allows for formatting a numeric type and rendering its digits in a specified base.

Functions

Converts a digit to a byte corresponding to a numeric or lowercase alphabetic char that represents the digit.

Converts a digit to a byte corresponding to a numeric or uppercase alphabetic char that represents the digit.